NekoHTML 1.9.22 throws an uncaught IllegalArgumentException when parsing an HTML attribute containing a numeric character reference greater than U+10FFFF.
The exception originates from Character.toChars() in HTMLScanner.appendChar() and propagates outside DOMParser.parse().
The issue is reproducible under the default parser configuration, without enabling report-errors. Applications processing untrusted HTML may experience request-level or document-processing failures if the unchecked exception is not handled.
net.sourceforge.nekohtml:nekohtml1.9.222.11.0Using NekoHTML 1.9.22, execute the following minimal Java program:
import java.io.StringReader;
import org.cyberneko.html.parsers.DOMParser;
import org.xml.sax.InputSource;
public class Repro {
public static void main(String[] args) throws Exception {
new DOMParser().parse(
new InputSource(
new StringReader("<div title=\"�\">x</div>")
)
);
}
}
The parser throws:
java.lang.IllegalArgumentException: Not a valid Unicode code point: 0x110000
at java.lang.Character.toChars(...)
at org.cyberneko.html.HTMLScanner.appendChar(HTMLScanner.java:1685)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanAttribute(HTMLScanner.java:3027)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanStartElement(HTMLScanner.java:2700)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
The exception occurs with both quoted and unquoted attribute values.
Out-of-range numeric character references should be treated as HTML parse errors and replaced with U+FFFD, rather than causing an unchecked exception to escape the parsing API.
NekoHTML already handles the same invalid reference correctly when it occurs in text content instead of an attribute.
| NekoHTML | Xerces | Result |
|---|---|---|
| 1.9.12 | 2.8.1 | Not reproduced |
| 1.9.16 | 2.9.1 | Not reproduced |
| 1.9.20 | 2.10.0 | Reproduced |
| 1.9.21 | 2.10.0 | Reproduced |
| 1.9.22 | 2.11.0 | Reproduced |
| 1.9.22 | 2.10.0 | Reproduced |
Versions 1.9.17–1.9.19 were not tested.
Additional tests confirmed that � and � also trigger the exception, while  is processed successfully.
When an application processes attacker-controlled HTML through NekoHTML, a specially crafted numeric character reference in an attribute may terminate the current parsing operation with an unchecked exception.
If the consuming application does not properly isolate or handle such exceptions, the issue may cause request failures or interruption of document-processing jobs.
This represents a potential context-dependent denial-of-service condition.
The current proof of concept demonstrates termination of an individual parse call. It does not demonstrate JVM termination, persistent service unavailability, or resource exhaustion.
The attribute scanning path passes an out-of-range Unicode code point to Character.toChars() without validating its range.
Relevant methods:
HTMLScanner.appendChar()HTMLScanner.ContentScanner.scanAttribute()The text-content scanning path already handles invalid character references differently.
Validate numeric character references before invoking Character.toChars().
For invalid Unicode code points, report an invalid character entity and substitute U+FFFD, consistently with the existing text-content parsing behavior.