From 9d2aecd69223469e40c12ca3edddda09009110cc Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Thu, 14 Apr 2022 19:34:11 +0200 Subject: [PATCH] fix oom exception --- .../htmlunit/cyberneko/HTMLScanner.java | 2 +- .../htmlunit/cyberneko/HTMLScannerTest.java | 18 ++++++++++++++++++ .../error-handling/test-broken-pi.html | 1 + .../test-broken-pi.html.canonical | 14 ++++++++++++++ .../test-broken-pi.html.settings | 2 ++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/error-handling/test-broken-pi.html create mode 100644 src/test/resources/error-handling/test-broken-pi.html.canonical create mode 100644 src/test/resources/error-handling/test-broken-pi.html.settings diff --git a/src/main/java/net/sourceforge/htmlunit/cyberneko/HTMLScanner.java b/src/main/java/net/sourceforge/htmlunit/cyberneko/HTMLScanner.java index c8b2d271..1209e9fe 100644 --- a/src/main/java/net/sourceforge/htmlunit/cyberneko/HTMLScanner.java +++ b/src/main/java/net/sourceforge/htmlunit/cyberneko/HTMLScanner.java @@ -2626,7 +2626,7 @@ protected void scanPI() throws IOException { if (c == '?' || c == '/') { final char c0 = (char)c; c = fCurrentEntity.read(); - if (c == '>') { + if (c == -1 || c == '>') { break; } fStringBuffer.append(c0); diff --git a/src/test/java/net/sourceforge/htmlunit/cyberneko/HTMLScannerTest.java b/src/test/java/net/sourceforge/htmlunit/cyberneko/HTMLScannerTest.java index 0e46e774..bfe89e8f 100644 --- a/src/test/java/net/sourceforge/htmlunit/cyberneko/HTMLScannerTest.java +++ b/src/test/java/net/sourceforge/htmlunit/cyberneko/HTMLScannerTest.java @@ -253,4 +253,22 @@ public void elementNameNormalization() throws Exception { final String[] expectedStringLower = {"(html", "(head", "(title", ")title", ")head", "(body", ")body", ")html"}; assertEquals(Arrays.asList(expectedStringLower).toString(), filter.collectedStrings.toString()); } + + /** + * Regression test for an oom exception in versions < 2.60. + * @throws Exception + */ + @Test + public void invalidProcessingInstruction() throws Exception { + final String string = "