From 10534265264247ccdc40d0ba59214b2b8e43d93d Mon Sep 17 00:00:00 2001 From: Rene Schwietzke Date: Wed, 13 Mar 2024 07:47:03 +0100 Subject: [PATCH] Ensure that reading more characters at the end of the buffer is not stopped due to the buffer appearing being at the end with reading, rather we read till we get a -1. Streams can deliver less than requested size and hence the buffer looks like it it almost finished, but it is technically not. --- src/main/java/org/htmlunit/cyberneko/HTMLScanner.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java b/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java index d35306d8..3a7f428a 100644 --- a/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java +++ b/src/main/java/org/htmlunit/cyberneko/HTMLScanner.java @@ -2341,10 +2341,8 @@ protected String nextContent(final int len) throws IOException { for (nbRead = 0; nbRead < len; ++nbRead) { // read() should not clear the buffer if (fCurrentEntity.offset_ == fCurrentEntity.length_) { - if (fCurrentEntity.length_ == fCurrentEntity.buffer_.length) { - fCurrentEntity.load(fCurrentEntity.buffer_.length); - } - else { // everything was already loaded + final int count = fCurrentEntity.load(fCurrentEntity.offset_); + if (count == -1) { break; } }