LibWeb: Fix division by zero on a zero-width viewport SVG image

We were previously crashing by a division by zero due to an aspect ratio
of zero on https://comicbookshop.co.nz/
This commit is contained in:
Shannon Booth 2024-05-19 14:24:52 +12:00 committed by Andreas Kling
parent be36dbce7d
commit d48316ce15
Notes: sideshowbarker 2024-07-17 02:23:25 +09:00
3 changed files with 23 additions and 2 deletions

View file

@ -155,9 +155,16 @@ Optional<CSSPixelFraction> SVGDecodedImageData::intrinsic_aspect_ratio() const
if (width.has_value() && height.has_value())
return *width / *height;
if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value())
return CSSPixels::nearest_value_for(viewbox->width) / CSSPixels::nearest_value_for(viewbox->height);
if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value()) {
auto viewbox_width = CSSPixels::nearest_value_for(viewbox->width);
if (viewbox_width == 0)
return {};
auto viewbox_height = CSSPixels::nearest_value_for(viewbox->height);
return viewbox_width / viewbox_height;
}
return {};
}