LibWeb: Treat near-zero aspect-ratios as degenerate

This commit is contained in:
Gingeh
2025-12-30 13:53:52 +11:00
committed by Jelle Raaijmakers
parent f9a996650b
commit 04b4cd9e00
2 changed files with 11 additions and 1 deletions

View File

@@ -91,7 +91,12 @@ Optional<CSSPixelFraction> Box::preferred_aspect_ratio() const
if (ratio.is_degenerate())
return {};
return CSSPixelFraction(ratio.numerator(), ratio.denominator());
auto fraction = CSSPixelFraction(ratio.numerator(), ratio.denominator());
// ratio.is_degenerate() operates on doubles while CSSPixelFraction uses CSSPixels, so we need to check again here.
if (fraction == 0)
return {};
return fraction;
}
}

View File

@@ -0,0 +1,5 @@
<!DOCTYPE html>
<title>CSS aspect-ratio: Doesn't crash with small but nonzero width/height in ratio</title>
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#aspect-ratio">
<div style="aspect-ratio: 1/0.00000000000001"></div>
<div style="aspect-ratio: 0.00000000000001/1"></div>