From 6d9fac934d8cc8b557b92d9a4b67533729053285 Mon Sep 17 00:00:00 2001 From: danfickle Date: Thu, 10 Dec 2020 23:03:13 +1100 Subject: [PATCH] #615 Don't try to create a box from an empty line-break result. This now triggers the endless loop detection code and crashes instead of infinite loop. To fix this completely we need to also fix the float clearing algorithm. --- .../src/main/java/com/openhtmltopdf/layout/Breaker.java | 2 ++ .../src/main/java/com/openhtmltopdf/layout/InlineBoxing.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java index 6efa09e55..749b21ee8 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java @@ -159,6 +159,8 @@ public static LineBreakResult breakText(LayoutContext c, break LOOP; } else { // We may be at the end of the line, so pick up at next line. + // FIXME: This is very dangerous and has led to infinite + // loops. Needs review. context.setEnd(savedEnd); break LOOP; } diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java index fddd8893b..b3e8ff1af 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlineBoxing.java @@ -441,7 +441,9 @@ private static StartInlineTextResult startInlineText( } if (!lbContext.isUnbreakable() || - (lbContext.isUnbreakable() && !current.line.isContainsContent())) { + (lbContext.isUnbreakable() && + !current.line.isContainsContent() && + lbContext.getEnd() > lbContext.getStart())) { // We can use the inline text by adding it to the current inline layout box. // We also mark the text as consumed by the line break context and reduce the width // we have remaining on this line.