Browse Source

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

Shannon Booth 1 year ago
parent
commit
dd20156010

+ 14 - 0
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 <html> at (0,0) content-size 800x600 [BFC] children: not-inline
+    BlockContainer <body> at (8,8) content-size 784x150 children: inline
+      frag 0 from ImageBox start: 0, length: 0, rect: [8,8 300x150] baseline: 150
+      ImageBox <img> 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 <svg> at (0,0) content-size 300x150 [SVG] children: not-inline
+      TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+  PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
+    PaintableWithLines (BlockContainer<BODY>) [8,8 784x150]
+      ImagePaintable (ImageBox<IMG>) [8,8 300x150]

+ 1 - 0
Tests/LibWeb/Layout/input/zero-height-viewport-svg-image.html

@@ -0,0 +1 @@
+<img src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2040%200'%3E%3C/svg%3E">

+ 2 - 0
Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp

@@ -162,6 +162,8 @@ Optional<CSSPixelFraction> 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;
     }