NekoHTML 1.9.22 contains an end-of-file handling defect in HTMLScanner.ContentScanner.scanPI() that can cause an infinite parsing loop, unbounded memory growth, or an uncaught ArrayIndexOutOfBoundsException when processing malformed HTML processing instructions.
The issue is reproducible under the default parser configuration with extremely small inputs:
<?x? triggers an uncaught ArrayIndexOutOfBoundsException.<!--!><?x? causes the parser to loop indefinitely, repeatedly appending characters to an internal buffer.The second case was independently reproduced with a 32 MiB heap limit, resulting in OutOfMemoryError. A related input discovered during Jazzer fuzzing kept the parser running for at least 1,588 seconds before the fuzzing watchdog terminated execution.
Applications that parse attacker-controlled HTML using NekoHTML may therefore be vulnerable to denial of service through CPU exhaustion, memory consumption, or stalled parsing threads.
net.sourceforge.nekohtml:nekohtml1.9.22org.cyberneko.html.HTMLScannerHTMLScanner.ContentScanner.scanPI()import java.io.StringReader;
import org.cyberneko.html.parsers.DOMParser;
import org.xml.sax.InputSource;
public class ReproA {
public static void main(String[] args) throws Exception {
new DOMParser().parse(
new InputSource(new StringReader("<?x?"))
);
}
}
Actual result:
java.lang.ArrayIndexOutOfBoundsException:
Index -1 out of bounds for length 2048
at org.cyberneko.html.HTMLScanner$CurrentEntity.read(HTMLScanner.java:1895)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanPI(HTMLScanner.java:2587)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2090)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
import java.io.StringReader;
import org.cyberneko.html.parsers.DOMParser;
import org.xml.sax.InputSource;
public class ReproB {
public static void main(String[] args) throws Exception {
new DOMParser().parse(
new InputSource(new StringReader("<!--!><?x?"))
);
}
}
Actual result:
The parser does not return. The parsing thread remains inside scanPI(), repeatedly executing the append-and-rewind logic.
Observed behavior:
OutOfMemoryError.HTMLScanner$ContentScanner.scanPI().The hanging case should be tested in a separate JVM process with an external timeout rather than inside an unrestricted test runner.
| NekoHTML Version | 4-byte Exception | 10-byte Hang/OOM |
|---|---|---|
| 1.9.12 | Reproduced | Throws exception instead |
| 1.9.16 | Reproduced | Reproduced |
| 1.9.20 | Reproduced | Reproduced |
| 1.9.21 | Reproduced | Reproduced |
| 1.9.22 | Reproduced | Reproduced |
Versions 1.9.17–1.9.19 were not tested.
The processing-instruction scanning loop in HTMLScanner.ContentScanner.scanPI() does not correctly handle EOF after a trailing ? or /.
When the scanner reads one of these characters, it looks ahead for >. If the following character is not >, the scanner appends the original character, rewinds the input, and continues.
When the lookahead reaches EOF, this logic can cause either:
The exact outcome depends on the parser's preceding input and entity-buffer state.
Malformed or unterminated processing instructions should be handled gracefully at EOF.
The parser should terminate normally or report a controlled parsing error. It must not enter an infinite loop, grow memory without bound, or throw an internal array-index exception.
A remote or local attacker who can supply HTML content to an application using NekoHTML may be able to trigger a denial-of-service condition.
The infinite-loop variant can occupy a parsing thread indefinitely and continuously consume heap memory. Repeated malicious requests may degrade service availability, depending on application-level timeouts, memory limits, and concurrency controls.
The proof of concept demonstrates parser-level nontermination and memory exhaustion. Service-wide availability impact depends on the consuming application.
Update HTMLScanner.ContentScanner.scanPI() to handle EOF explicitly during lookahead.
When a trailing ? or / is followed by EOF, the scanner should terminate the processing-instruction parsing loop without rewinding beyond the valid input boundary.
The fix should also include regression tests for:
<?x?<?x/<!--><?x?<?x?>Both exception-triggering and nonterminating input variants should be covered.
The issue was identified during differential fuzzing of four Java HTML parsers using Jazzer and subsequently minimized into deterministic 4-byte and 10-byte reproducer inputs.
The tested alternative parsers (jsoup, validator.nu HTML Parser, and TagSoup) completed processing of the corresponding inputs without hanging.