From 1263d586895b58506084733bee8c6f0cfc803a15 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Mon, 21 Jul 2025 04:47:55 +0100 Subject: [PATCH] LibWeb: Ignore zero width when calculating SVG intrinsic aspect ratio Previously, an SVG with width of zero would have am intrinsic aspect ratio of zero. With this change, if an SVG has a width or height of zero, the intrinsic aspect ratio is determined by the SVG's viewbox. --- Libraries/LibWeb/SVG/SVGDecodedImageData.cpp | 5 +---- Tests/LibWeb/Crash/SVG/zero-width-svg.html | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Crash/SVG/zero-width-svg.html diff --git a/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index aae5ea9c5f6..fa6ffee2ce9 100644 --- a/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -172,10 +172,7 @@ Optional SVGDecodedImageData::intrinsic_aspect_ratio() const // https://www.w3.org/TR/SVG2/coords.html#SizingSVGInCSS auto width = intrinsic_width(); auto height = intrinsic_height(); - if (height.has_value() && *height == 0) - return {}; - - if (width.has_value() && height.has_value()) + if (width.has_value() && height.has_value() && *width > 0 && *height > 0) return *width / *height; if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value()) { diff --git a/Tests/LibWeb/Crash/SVG/zero-width-svg.html b/Tests/LibWeb/Crash/SVG/zero-width-svg.html new file mode 100644 index 00000000000..7cce33f5081 --- /dev/null +++ b/Tests/LibWeb/Crash/SVG/zero-width-svg.html @@ -0,0 +1,2 @@ + +