Bug 224310 - Division by zero in WebCore::RenderGrid::computeAutoRepeatTracksCount (RenderGrid.cpp:525)
Summary: Division by zero in WebCore::RenderGrid::computeAutoRepeatTracksCount (Render...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Rob Buis
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-07 16:07 PDT by Ryosuke Niwa
Modified: 2021-04-12 08:09 PDT (History)
20 users (show)

See Also:


Attachments
Test (406 bytes, text/html)
2021-04-07 16:08 PDT, Ryosuke Niwa
no flags Details
Patch (4.26 KB, patch)
2021-04-08 01:36 PDT, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (4.33 KB, patch)
2021-04-09 04:35 PDT, Rob Buis
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2021-04-07 16:07:50 PDT
e.g.

ASSERTION FAILED: !availableSize || *availableSize >= 0
./rendering/RenderGrid.cpp(316) : WebCore::LayoutUnit WebCore::RenderGrid::gridGap(WebCore::GridTrackSizingDirection, Optional<WebCore::LayoutUnit>) const
1   0x5c6b33bf9 WTFCrash
2   0x5a90534cb WTFCrashWithInfo(int, char const*, char const*, int)
3   0x5ad61d0e2 WebCore::RenderGrid::gridGap(WebCore::GridTrackSizingDirection, WTF::Optional<WebCore::LayoutUnit>) const
4   0x5ad61e66f WebCore::RenderGrid::computeAutoRepeatTracksCount(WebCore::GridTrackSizingDirection, WTF::Optional<WebCore::LayoutUnit>) const
5   0x5ad61c36f WebCore::RenderGrid::placeItemsOnGrid(WebCore::GridTrackSizingAlgorithm&, WTF::Optional<WebCore::LayoutUnit>) const
6   0x5ad61bc9c WebCore::RenderGrid::layoutBlock(bool, WebCore::LayoutUnit)
7   0x5ad6a1c42 WebCore::RenderLayerScrollableArea::updateScrollbarsAfterLayout()
8   0x5ad65938c WebCore::RenderLayerScrollableArea::updateScrollInfoAfterLayout()
9   0x5ad6591b5 WebCore::RenderLayer::updateScrollInfoAfterLayout()
10  0x5ad506db2 WebCore::RenderBlock::endAndCommitUpdateScrollInfoAfterLayoutTransaction()
11  0x5ad61c0df WebCore::RenderGrid::layoutBlock(bool, WebCore::LayoutUnit)
12  0x5ad507179 WebCore::RenderBlock::layout()
13  0x5ad522182 WebCore::RenderBlockFlow::layoutBlockChild(WebCore::RenderBox&, WebCore::RenderBlockFlow::MarginInfo&, WebCore::LayoutUnit&, WebCore::LayoutUnit&)
14  0x5ad520b14 WebCore::RenderBlockFlow::layoutBlockChildren(bool, WebCore::LayoutUnit&)
15  0x5ad51f993 WebCore::RenderBlockFlow::layoutBlock(bool, WebCore::LayoutUnit)
16  0x5ad507179 WebCore::RenderBlock::layout()
17  0x5ad7a6313 WebCore::RenderView::layout()
18  0x5acc89901 WebCore::FrameViewLayoutContext::layout()
19  0x5abeb2836 WebCore::Document::implicitClose()
20  0x5aca8159b WebCore::FrameLoader::checkCallImplicitClose()
21  0x5aca80fca WebCore::FrameLoader::checkCompleted()
22  0x5aca7f0b7 WebCore::FrameLoader::finishedParsing()
23  0x5abec7476 WebCore::Document::finishedParsing()
24  0x5ac6010d8 WebCore::HTMLConstructionSite::finishedParsing()
25  0x5ac646f57 WebCore::HTMLTreeBuilder::finished()
26  0x5ac608708 WebCore::HTMLDocumentParser::end()
27  0x5ac6063d8 WebCore::HTMLDocumentParser::attemptToRunDeferredScriptsAndEnd()
28  0x5ac606117 WebCore::HTMLDocumentParser::prepareToStopParsing()
29  0x5ac608772 WebCore::HTMLDocumentParser::attemptToEnd()
30  0x5ac608839 WebCore::HTMLDocumentParser::finish()
31  0x5aca58e44 WebCore::DocumentWriter::end()
#CRASHED - com.apple.WebKit.WebContent.Development (pid 2680)

<rdar://76344587>
Comment 1 Ryosuke Niwa 2021-04-07 16:08:07 PDT
Debug assertion:
ASSERTION FAILED: !availableSize || *availableSize >= 0
./rendering/RenderGrid.cpp(316) : WebCore::LayoutUnit WebCore::RenderGrid::gridGap(WebCore::GridTrackSizingDirection, Optional<WebCore::LayoutUnit>) const
1   0x5c6b33bf9 WTFCrash
2   0x5a90534cb WTFCrashWithInfo(int, char const*, char const*, int)
3   0x5ad61d0e2 WebCore::RenderGrid::gridGap(WebCore::GridTrackSizingDirection, WTF::Optional<WebCore::LayoutUnit>) const
4   0x5ad61e66f WebCore::RenderGrid::computeAutoRepeatTracksCount(WebCore::GridTrackSizingDirection, WTF::Optional<WebCore::LayoutUnit>) const
5   0x5ad61c36f WebCore::RenderGrid::placeItemsOnGrid(WebCore::GridTrackSizingAlgorithm&, WTF::Optional<WebCore::LayoutUnit>) const
6   0x5ad61bc9c WebCore::RenderGrid::layoutBlock(bool, WebCore::LayoutUnit)
7   0x5ad6a1c42 WebCore::RenderLayerScrollableArea::updateScrollbarsAfterLayout()
8   0x5ad65938c WebCore::RenderLayerScrollableArea::updateScrollInfoAfterLayout()
9   0x5ad6591b5 WebCore::RenderLayer::updateScrollInfoAfterLayout()
10  0x5ad506db2 WebCore::RenderBlock::endAndCommitUpdateScrollInfoAfterLayoutTransaction()
11  0x5ad61c0df WebCore::RenderGrid::layoutBlock(bool, WebCore::LayoutUnit)
12  0x5ad507179 WebCore::RenderBlock::layout()
13  0x5ad522182 WebCore::RenderBlockFlow::layoutBlockChild(WebCore::RenderBox&, WebCore::RenderBlockFlow::MarginInfo&, WebCore::LayoutUnit&, WebCore::LayoutUnit&)
14  0x5ad520b14 WebCore::RenderBlockFlow::layoutBlockChildren(bool, WebCore::LayoutUnit&)
15  0x5ad51f993 WebCore::RenderBlockFlow::layoutBlock(bool, WebCore::LayoutUnit)
16  0x5ad507179 WebCore::RenderBlock::layout()
17  0x5ad7a6313 WebCore::RenderView::layout()
18  0x5acc89901 WebCore::FrameViewLayoutContext::layout()
19  0x5abeb2836 WebCore::Document::implicitClose()
20  0x5aca8159b WebCore::FrameLoader::checkCallImplicitClose()
21  0x5aca80fca WebCore::FrameLoader::checkCompleted()
22  0x5aca7f0b7 WebCore::FrameLoader::finishedParsing()
23  0x5abec7476 WebCore::Document::finishedParsing()
24  0x5ac6010d8 WebCore::HTMLConstructionSite::finishedParsing()
25  0x5ac646f57 WebCore::HTMLTreeBuilder::finished()
26  0x5ac608708 WebCore::HTMLDocumentParser::end()
27  0x5ac6063d8 WebCore::HTMLDocumentParser::attemptToRunDeferredScriptsAndEnd()
28  0x5ac606117 WebCore::HTMLDocumentParser::prepareToStopParsing()
29  0x5ac608772 WebCore::HTMLDocumentParser::attemptToEnd()
30  0x5ac608839 WebCore::HTMLDocumentParser::finish()
31  0x5aca58e44 WebCore::DocumentWriter::end()
#CRASHED - com.apple.WebKit.WebContent.Development (pid 2680)
Comment 2 Ryosuke Niwa 2021-04-07 16:08:31 PDT
I can reproduce this with WebKitTestRunner at r275541.
Comment 3 Ryosuke Niwa 2021-04-07 16:08:48 PDT
Created attachment 425448 [details]
Test
Comment 4 Rob Buis 2021-04-08 01:36:43 PDT
Created attachment 425484 [details]
Patch
Comment 5 Ryosuke Niwa 2021-04-08 11:55:23 PDT
There is no security implication here, right?
Comment 6 Rob Buis 2021-04-08 12:35:28 PDT
(In reply to Ryosuke Niwa from comment #5)
> There is no security implication here, right?

I do not think so, correct.
Comment 7 Manuel Rego Casasnovas 2021-04-09 00:59:10 PDT
Comment on attachment 425484 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=425484&action=review

The fix LGTM, I'm surprised we don't have clampNegativeToZero() for LayoutUnits in WebKit, but essentially is the same that you're doing there.

> Source/WebCore/rendering/RenderBox.h:324
> +    LayoutUnit overridingContentLogicalHeight() const { return std::max(LayoutUnit(), overridingLogicalHeight() - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight()); }

I'm wondering why were not clamping this before, I believe Sergio introduced this code recently. It'd be nice to know his thoughts on this.

> LayoutTests/fast/css-grid-layout/negative-overriding-content-logical-height-crash.html:1
> +<style>

This test is very weird, can we get a reduced version of it, not sure if we need such a bunch of nested inline-grids.

Also this is using quirks mode, is that needed?

Another question, can we just put the test under WPT?

> LayoutTests/fast/css-grid-layout/negative-overriding-content-logical-height-crash.html:4
> +    overflow-y: hidden;

Does this affect the test?

> LayoutTests/fast/css-grid-layout/negative-overriding-content-logical-height-crash.html:7
> +  style, body, head, div {

"head" here doesn't look needed, but dunno.

"style" here is kind of weird too, but maybe it's needed.
Comment 8 Sergio Villar Senin 2021-04-09 01:49:24 PDT
Comment on attachment 425484 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=425484&action=review

>> Source/WebCore/rendering/RenderBox.h:324
>> +    LayoutUnit overridingContentLogicalHeight() const { return std::max(LayoutUnit(), overridingLogicalHeight() - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight()); }
> 
> I'm wondering why were not clamping this before, I believe Sergio introduced this code recently. It'd be nice to know his thoughts on this.

Well I am basically not sure who should do the clamping. Negative values make sense in flexbox for example but only as intermediate results of the algorithm, not in the final results.

That said I guess the question here is whether negative overriding sizes make sense. This would define who should do the clamping, either here or in the caller. I guess they don't, so this could be correct.

>> LayoutTests/fast/css-grid-layout/negative-overriding-content-logical-height-crash.html:4
>> +    overflow-y: hidden;
> 
> Does this affect the test?

I would bet that the first to 0's are not needed, it might be enough with having a 1px column before the auto repeat.

Also agree with Rego about trying to reduce it a bit more.
Comment 9 Rob Buis 2021-04-09 04:35:36 PDT
Created attachment 425607 [details]
Patch
Comment 10 Rob Buis 2021-04-09 06:09:53 PDT
Comment on attachment 425484 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=425484&action=review

>>> LayoutTests/fast/css-grid-layout/negative-overriding-content-logical-height-crash.html:4
>>> +    overflow-y: hidden;
>> 
>> Does this affect the test?
> 
> I would bet that the first to 0's are not needed, it might be enough with having a 1px column before the auto repeat.
> 
> Also agree with Rego about trying to reduce it a bit more.

Rego and myself found out for the division by zero problem to reproduce, we do need Ryosuke's original test case, so I reverted back to that one.
Comment 11 EWS 2021-04-12 08:09:05 PDT
Committed r275823 (236393@main): <https://commits.webkit.org/236393@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 425607 [details].