Menu ▾ ▴

#168 Uncaught IllegalArgumentException in NekoHTML 1.9.22 when parsing out-of-range Unicode references in attributes

1.9.15
open
nobody
None
5
2026-10-29
2026-10-29
Wang xinxin
No

Summary

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.

Environment

  • Component: net.sourceforge.nekohtml:nekohtml
  • Latest tested version: 1.9.22
  • Xerces dependency: 2.11.0
  • JDK: 17
  • OS: Linux
  • Potential weakness: CWE-248 (Uncaught Exception)

Steps to Reproduce

Using 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=\"&#x110000;\">x</div>")
            )
        );
    }
}

Actual Result

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.

Expected Result

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.

Affected Version Matrix

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 &#x110001; and &#x7FFFFFFF; also trigger the exception, while &#x10FFFF; is processed successfully.

Potential Security Impact

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.

Root Cause

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.

Suggested Fix

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.

Discussion


Log in to post a comment.