Changeset 273470 in webkit


Ignore:
Timestamp:
Feb 24, 2021 9:59:46 PM (17 months ago)
Author:
commit-queue@webkit.org
Message:

[css-grid] Do not allow negative heights
https://bugs.webkit.org/show_bug.cgi?id=221439

Patch by Rob Buis <rbuis@igalia.com> on 2021-02-24
Reviewed by Darin Adler.

Source/WebCore:

Do not allow negative heights in calculations, instead
use Optional to indicate that the heights are not existing.

Test: fast/css-grid-layout/zero-height-crash.html

  • rendering/GridTrackSizingAlgorithm.cpp:

(WebCore::DefiniteSizeStrategy::minLogicalSizeForChild const):

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::replacedMinMaxLogicalHeightComputesAsNone const):

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::gridGap const):
(WebCore::RenderGrid::placeItemsOnGrid const):
(WebCore::RenderGrid::applyStretchAlignmentToChildIfNeeded):

LayoutTests:

Add test for this.

  • fast/css-grid-layout/zero-height-crash-expected.txt: Added.
  • fast/css-grid-layout/zero-height-crash.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r273467 r273470  
     12021-02-24  Rob Buis  <rbuis@igalia.com>
     2
     3        [css-grid] Do not allow negative heights
     4        https://bugs.webkit.org/show_bug.cgi?id=221439
     5
     6        Reviewed by Darin Adler.
     7
     8        Add test for this.
     9
     10        * fast/css-grid-layout/zero-height-crash-expected.txt: Added.
     11        * fast/css-grid-layout/zero-height-crash.html: Added.
     12
    1132021-02-24  Imanol Fernandez  <ifernandez@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r273468 r273470  
     12021-02-24  Rob Buis  <rbuis@igalia.com>
     2
     3        [css-grid] Do not allow negative heights
     4        https://bugs.webkit.org/show_bug.cgi?id=221439
     5
     6        Reviewed by Darin Adler.
     7
     8        Do not allow negative heights in calculations, instead
     9        use Optional to indicate that the heights are not existing.
     10
     11        Test: fast/css-grid-layout/zero-height-crash.html
     12
     13        * rendering/GridTrackSizingAlgorithm.cpp:
     14        (WebCore::DefiniteSizeStrategy::minLogicalSizeForChild const):
     15        * rendering/RenderBox.cpp:
     16        (WebCore::RenderBox::replacedMinMaxLogicalHeightComputesAsNone const):
     17        * rendering/RenderGrid.cpp:
     18        (WebCore::RenderGrid::layoutBlock):
     19        (WebCore::RenderGrid::gridGap const):
     20        (WebCore::RenderGrid::placeItemsOnGrid const):
     21        (WebCore::RenderGrid::applyStretchAlignmentToChildIfNeeded):
     22
    1232021-02-24  Julian Gonzalez  <julian_a_gonzalez@apple.com>
    224
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp

    r272805 r273470  
    10531053{
    10541054    GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
    1055     LayoutUnit indefiniteSize = direction() == childInlineDirection ? LayoutUnit() : LayoutUnit(-1);
    10561055    GridTrackSizingDirection flowAwareDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, direction());
    1057     if (hasRelativeMarginOrPaddingForChild(child, flowAwareDirection) || (direction() != childInlineDirection && hasRelativeOrIntrinsicSizeForChild(child, flowAwareDirection)))
    1058         setOverridingContainingBlockContentSizeForChild(child, direction(), indefiniteSize);
     1056    if (hasRelativeMarginOrPaddingForChild(child, flowAwareDirection) || (direction() != childInlineDirection && hasRelativeOrIntrinsicSizeForChild(child, flowAwareDirection))) {
     1057        Optional<LayoutUnit> overridingSize;
     1058        if (direction() == childInlineDirection)
     1059            overridingSize = 0_lu;
     1060        setOverridingContainingBlockContentSizeForChild(child, direction(), overridingSize);
     1061    }
    10591062    return GridTrackSizingAlgorithmStrategy::minLogicalSizeForChild(child, childMinSize, availableSize);
    10601063}
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r273435 r273470  
    32803280   
    32813281    if (logicalHeight.isPercentOrCalculated() && hasOverridingContainingBlockContentLogicalHeight())
    3282         return overridingContainingBlockContentLogicalHeight() == LayoutUnit(-1);
     3282        return false;
    32833283
    32843284    // Make sure % min-height and % max-height resolve to none if the containing block has auto height.
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r272307 r273470  
    251251            computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForRows);
    252252        else
    253             computeTrackSizesForDefiniteSize(ForRows, availableLogicalHeight(ExcludeMarginBorderPadding));
     253            computeTrackSizesForDefiniteSize(ForRows, std::max<LayoutUnit>(0_lu, availableLogicalHeight(ExcludeMarginBorderPadding)));
    254254        LayoutUnit trackBasedLogicalHeight = m_trackSizingAlgorithm.computeTrackBasedSize() + borderAndPaddingLogicalHeight() + scrollbarLogicalHeight();
    255255        setLogicalHeight(trackBasedLogicalHeight);
     
    311311LayoutUnit RenderGrid::gridGap(GridTrackSizingDirection direction, Optional<LayoutUnit> availableSize) const
    312312{
     313    ASSERT(!availableSize || *availableSize >= 0);
    313314    const GapLength& gapLength = direction == ForColumns? style().columnGap() : style().rowGap();
    314315    if (gapLength.isNormal())
     
    614615            child->setOverridingContainingBlockContentLogicalWidth(LayoutUnit());
    615616        if (!child->hasOverridingContainingBlockContentLogicalHeight())
    616             child->setOverridingContainingBlockContentLogicalHeight(LayoutUnit(-1));
     617            child->setOverridingContainingBlockContentLogicalHeight(WTF::nullopt);
    617618
    618619        GridArea area = grid.gridItemArea(*child);
     
    11371138    if (allowedToStretchChildBlockSize) {
    11381139        LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child);
    1139         LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, -1_lu);
     1140        LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, WTF::nullopt);
    11401141        child.setOverridingLogicalHeight(desiredLogicalHeight);
    11411142
Note: See TracChangeset for help on using the changeset viewer.