diff --git a/third_party/WebKit/Source/core/layout/LayoutTable.cpp b/third_party/WebKit/Source/core/layout/LayoutTable.cpp index 2c8d2ab4627a6..4299eb8aec4e7 100644 --- a/third_party/WebKit/Source/core/layout/LayoutTable.cpp +++ b/third_party/WebKit/Source/core/layout/LayoutTable.cpp @@ -1664,16 +1664,18 @@ void LayoutTable::UpdateCollapsedOuterBorders() const { } } - const auto* bottom_section = BottomNonEmptySection(); - DCHECK(bottom_section); // The table's after outer border width is the maximum after outer border // widths of all cells in the last row. See the CSS 2.1 spec, section 17.6.2. - unsigned row = bottom_section->NumRows() - 1; - unsigned bottom_cols = bottom_section->NumCols(row); - for (unsigned col = 0; col < bottom_cols; ++col) { - if (const auto* cell = bottom_section->PrimaryCellAt(row, col)) { - collapsed_outer_border_after_ = std::max( - collapsed_outer_border_after_, cell->CollapsedOuterBorderAfter()); + // TODO(crbug.com/764525): Because of the bug, bottom_section can be null when + // top_section is not null. See LayoutTableTest.OutOfOrderHeadAndBody. + if (const auto* bottom_section = BottomNonEmptySection()) { + unsigned row = bottom_section->NumRows() - 1; + unsigned bottom_cols = bottom_section->NumCols(row); + for (unsigned col = 0; col < bottom_cols; ++col) { + if (const auto* cell = bottom_section->PrimaryCellAt(row, col)) { + collapsed_outer_border_after_ = std::max( + collapsed_outer_border_after_, cell->CollapsedOuterBorderAfter()); + } } } diff --git a/third_party/WebKit/Source/core/layout/LayoutTableTest.cpp b/third_party/WebKit/Source/core/layout/LayoutTableTest.cpp index 82fd163303f1e..cc4a25fda5bf5 100644 --- a/third_party/WebKit/Source/core/layout/LayoutTableTest.cpp +++ b/third_party/WebKit/Source/core/layout/LayoutTableTest.cpp @@ -233,6 +233,18 @@ TEST_F(LayoutTableTest, PaddingWithCollapsedBorder) { EXPECT_EQ(0, table->PaddingUnder()); } +TEST_F(LayoutTableTest, OutOfOrderHeadAndBody) { + // This should not crash. + SetBodyInnerHTML( + "
Body |