Commit 5fb2b257 authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[AspectRatio] Fix divide by zero with a small float ratio

A small float number will convert to a zero layout unit, leading to a
division by zero.

R=ikilpatrick@chromium.org, mstensho@chromium.org

Fixed: 1137262, 1137264, 1137471, 1137227
Change-Id: Iea57ab61369570f08e74384a763e6ec4f2fa155e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2475453
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817454}
parent 9bad137f
......@@ -25,6 +25,12 @@ class StyleAspectRatio {
EAspectRatioType GetType() const {
if (ratio_.Width() == 0 || ratio_.Height() == 0)
return EAspectRatioType::kAuto;
// Since we do calculations on LayoutUnits, also check that our width/height
// doesn't convert to zero.
if (ratio_.Width() < LayoutUnit::Epsilon() ||
ratio_.Height() < LayoutUnit::Epsilon()) {
return EAspectRatioType::kAuto;
}
return GetTypeForComputedStyle();
}
......
<!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>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment