Skip to content

Commit

Permalink
Fixes #466 - Infinite loop bug with zero width boxes using break-word.
Browse files Browse the repository at this point in the history
Big thanks to @syjer for finding out where to start debugging this bug.
  • Loading branch information
danfickle committed Apr 30, 2020
1 parent bf717f4 commit c5d5452
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ static LineBreakResult doBreakCharacters(
nextCharBreak = charIterator.next();
}

if (graphicsLength == avail) {
if (graphicsLength == avail &&
graphicsLength > 0) {
// Exact fit..
boolean needNewLine = currentString.length() > left;

Expand Down Expand Up @@ -314,7 +315,8 @@ static LineBreakResult doBreakCharacters(
graphicsLength += splitWidth;
}

if (graphicsLength <= avail) {
if (graphicsLength <= avail &&
graphicsLength > 0) {
// The entire word fit.
context.setWidth(graphicsLength);
context.setEnd(nextCharBreak + context.getStart());
Expand Down Expand Up @@ -361,6 +363,7 @@ static LineBreakResult doBreakCharacters(
// Empty string.
context.setEnd(context.getStart());
context.setWidth(0);
context.setNeedsNewLine(false);

return LineBreakResult.CHAR_BREAKING_FINISHED;
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
<div>

<!-- Width zero with content -->
<div style="width: 0;">GHI</div>
<div style="width: 0; word-wrap: break-word;">DEF</div>

<!-- Width zero with breakable content -->
<div style="width: 0;">PQR STU</div>
<div style="width: 0; word-wrap: break-word;">VWX 123</div>

<!-- Width zero with no content -->
<div style="width: 0;"></div>
<div style="width: 0; word-wrap: break-word;"></div>

<!-- Negative content width with content -->
<div style="box-sizing: border-box; width: 5px; padding: 0 5px;">JKL</div>
<div style="box-sizing: border-box; width: 5px; padding: 0 5px; word-wrap: break-word;">MNO</div>

<!-- Negative content width without content -->
<div style="box-sizing: border-box; width: 5px; padding: 0 5px;"></div>
<div style="box-sizing: border-box; width: 5px; padding: 0 5px; word-wrap: break-word;"></div>

<!-- Zero width table cell as result of layout -->
<table style="width: 3px;table-layout: fixed;">
<tr>
<td colspan="2"></td>
<td style="word-wrap: break-word;">ABC</td>
</tr>
</table>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,12 @@ public void testIssue459RemUnitDefault() throws IOException {
/**
* Tests a reported infinite loop bug with table cells in specific
* circumstances.
*
* Turns out this bug was triggered by zero width table cells
* with content and word-wrap: break-word. Therefore, this test
* also exercises zero width divs with content (and without).
*/
@Test
@Ignore // Infinite loop w memory allocation.
public void testIssue466InfiniteLoopTableCellBox() throws IOException {
assertTrue(vt.runTest("issue-466-infinite-loop-table-cell-box"));
}
Expand Down

0 comments on commit c5d5452

Please sign in to comment.