mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-19 01:08:18 +03:00
LibWeb: Avoid division by zero when calculating SVG viewbox aspect ratio
This commit is contained in:
parent
b61aab66d9
commit
e9383b9c86
Notes:
sideshowbarker
2024-07-17 09:49:48 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/e9383b9c86 Pull-request: https://github.com/SerenityOS/serenity/pull/23616
@ -0,0 +1 @@
|
||||
PASS (didn't crash)
|
10
Tests/LibWeb/Text/input/SVG/svg-viewbox-zero-height.html
Normal file
10
Tests/LibWeb/Text/input/SVG/svg-viewbox-zero-height.html
Normal file
@ -0,0 +1,10 @@
|
||||
<script src="../include.js"></script>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" id="svg-element"></svg>
|
||||
<script>
|
||||
test(() => {
|
||||
const svgElement = document.getElementById("svg-element");
|
||||
svgElement.height = 1;
|
||||
svgElement.setAttribute("viewBox", "0 0 1 0");
|
||||
println("PASS (didn't crash)");
|
||||
});
|
||||
</script>
|
@ -73,7 +73,11 @@ Optional<CSSPixelFraction> SVGSVGBox::calculate_intrinsic_aspect_ratio() const
|
||||
auto const& viewbox = dom_node().view_box().value();
|
||||
|
||||
// 2. return viewbox.width / viewbox.height
|
||||
return CSSPixels::nearest_value_for(viewbox.width) / CSSPixels::nearest_value_for(viewbox.height);
|
||||
auto height = CSSPixels::nearest_value_for(viewbox.height);
|
||||
if (height != 0)
|
||||
return CSSPixels::nearest_value_for(viewbox.width) / CSSPixels::nearest_value_for(viewbox.height);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// 4. return null
|
||||
|
Loading…
Reference in New Issue
Block a user