Commit b3ad25f1 authored by Aleks Totic's avatar Aleks Totic Committed by Commit Bot

[LayoutNG] Fix clusterfuzz crash

Using empty Optional<MinMax> to indicate that MinMax value
should not matter caused trouble with ng_length_utils
ResolveInlineLengthInternal, when max-width was fit-content.

Use MinMax(0, LayoutUnitMax) to indicate intrinsic size does
not matter instead. It accomplishes the same goal, computed
size does not get clamped by intrinsic.

I've also tested running it with width:max-content out of
fear that we might end up with too wide OOF, but that did
not happen.

Bug: 1010798
Change-Id: Ife11b3d9637be91cc0648b7f8485af51f07108bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837118
Commit-Queue: Aleks Totic <atotic@chromium.org>
Auto-Submit: Aleks Totic <atotic@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702525}
parent bc3c0990
...@@ -70,19 +70,14 @@ inline LayoutUnit StaticPositionEndInset(bool is_static_position_start, ...@@ -70,19 +70,14 @@ inline LayoutUnit StaticPositionEndInset(bool is_static_position_start,
(is_static_position_start ? size : LayoutUnit()); (is_static_position_start ? size : LayoutUnit());
} }
// https://www.w3.org/TR/css-position-3/#abs-replaced-width
// Handle the special case of an element with aspect ratio, but no intrinsic
// width or height.
LayoutUnit ComputeShrinkToFitSize( LayoutUnit ComputeShrinkToFitSize(
const base::Optional<MinMaxSize>& child_minmax, const base::Optional<MinMaxSize>& child_minmax,
LayoutUnit computed_available_size, LayoutUnit computed_available_size,
LayoutUnit margin_start, LayoutUnit margin_start,
LayoutUnit margin_end) { LayoutUnit margin_end) {
LayoutUnit size = (computed_available_size - margin_start - margin_end) return child_minmax->ShrinkToFit(
.ClampNegativeToZero(); (computed_available_size - margin_start - margin_end)
if (child_minmax) .ClampNegativeToZero());
return child_minmax->ShrinkToFit(size);
return size;
} }
// Implement the absolute size resolution algorithm. // Implement the absolute size resolution algorithm.
......
...@@ -584,7 +584,7 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::Layout( ...@@ -584,7 +584,7 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::Layout(
// should not be constrained by intrinsic size in this case. // should not be constrained by intrinsic size in this case.
// https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-width // https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-width
if (is_replaced_with_only_aspect_ratio) if (is_replaced_with_only_aspect_ratio)
min_max_size.reset(); min_max_size = MinMaxSize{LayoutUnit(), LayoutUnit::NearlyMax()};
} else if (should_be_considered_as_replaced) { } else if (should_be_considered_as_replaced) {
replaced_size = replaced_size =
LogicalSize{min_max_size->ShrinkToFit( LogicalSize{min_max_size->ShrinkToFit(
......
...@@ -261,7 +261,14 @@ ...@@ -261,7 +261,14 @@
<!-- Just viewbox. Has aspect_ratio, but no intrinsic size <!-- Just viewbox. Has aspect_ratio, but no intrinsic size
inline_width is constrained by left/right, height computed proportionally --> inline_width is constrained by left/right, height computed proportionally -->
<div class="container"> <div class="container">
<img class="target" style="left:100px;right:100px" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E" <img class="target" style="left:100px;right:100px;" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
data-expected-width="188" data-expected-height="47" data-offset-y="146" data-offset-x="109"
>
</div>
<!-- Same as previous test, but with max-width:fit-content. crbug.com/1010798
-->
<div class="container">
<img class="target" style="left:100px;right:100px;max-width:fit-content" src="data:image/svg+xml,%3Csvg viewBox='0 0 100 10' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' style='fill:rgb(0,255,0);'/%3E%3C/svg%3E"
data-expected-width="188" data-expected-height="47" data-offset-y="146" data-offset-x="109" data-expected-width="188" data-expected-height="47" data-offset-y="146" data-offset-x="109"
> >
</div> </div>
......
...@@ -35,7 +35,8 @@ PASS minmax replaced IMG svg 33 ...@@ -35,7 +35,8 @@ PASS minmax replaced IMG svg 33
PASS minmax replaced IMG 34 PASS minmax replaced IMG 34
FAIL minmax replaced IMG 35 assert_equals: incorrect offsetWidth expected "388" but got "426" FAIL minmax replaced IMG 35 assert_equals: incorrect offsetWidth expected "388" but got "426"
FAIL minmax replaced IMG 36 assert_equals: incorrect offsetWidth expected "188" but got "426" FAIL minmax replaced IMG 36 assert_equals: incorrect offsetWidth expected "188" but got "426"
PASS minmax replaced IMG 37 FAIL minmax replaced IMG 37 assert_equals: incorrect offsetWidth expected "188" but got "338"
PASS minmax replaced IMG 38 PASS minmax replaced IMG 38
PASS minmax replaced IMG 39
Harness: the test ran to completion. Harness: the test ran to completion.
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