From dd201560104b220dfb59b7acdba1a024b968328c Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 19 May 2024 15:34:56 +1200 Subject: [PATCH] LibWeb: Fix division by zero on a zero-height viewport SVG image --- .../expected/zero-height-viewport-svg-image.txt | 14 ++++++++++++++ .../input/zero-height-viewport-svg-image.html | 1 + .../Libraries/LibWeb/SVG/SVGDecodedImageData.cpp | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/zero-height-viewport-svg-image.txt create mode 100644 Tests/LibWeb/Layout/input/zero-height-viewport-svg-image.html diff --git a/Tests/LibWeb/Layout/expected/zero-height-viewport-svg-image.txt b/Tests/LibWeb/Layout/expected/zero-height-viewport-svg-image.txt new file mode 100644 index 00000000000..20d76525089 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/zero-height-viewport-svg-image.txt @@ -0,0 +1,14 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x150 children: inline + frag 0 from ImageBox start: 0, length: 0, rect: [8,8 300x150] baseline: 150 + ImageBox at (8,8) content-size 300x150 children: not-inline + (SVG-as-image isolated context) + Viewport <#document> at (0,0) content-size 300x150 [BFC] children: inline + SVGSVGBox at (0,0) content-size 300x150 [SVG] children: not-inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x150] + ImagePaintable (ImageBox) [8,8 300x150] diff --git a/Tests/LibWeb/Layout/input/zero-height-viewport-svg-image.html b/Tests/LibWeb/Layout/input/zero-height-viewport-svg-image.html new file mode 100644 index 00000000000..b2e17c359f8 --- /dev/null +++ b/Tests/LibWeb/Layout/input/zero-height-viewport-svg-image.html @@ -0,0 +1 @@ + diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index c06bf77ea85..f1cf18bd602 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -162,6 +162,8 @@ Optional SVGDecodedImageData::intrinsic_aspect_ratio() const return {}; auto viewbox_height = CSSPixels::nearest_value_for(viewbox->height); + if (viewbox_height == 0) + return {}; return viewbox_width / viewbox_height; }