NekoHTML 1.9.22 throws an uncaught ArrayIndexOutOfBoundsException when parsing an HTML start tag containing duplicate bare xmlns: attributes at the fifth or a later attribute position.
The issue is reproducible under the default parser configuration and originates from incorrect attribute index handling in HTMLTagBalancer.Info.
net.sourceforge.nekohtml:nekohtml:1.9.22xerces:xercesImpl:2.11.0Run the following standalone Java program with NekoHTML 1.9.22:
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("<s xmlns: xmlns: xmlns: xmlns: xmlns:>")
));
}
}
The parser throws:
java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
at org.apache.xerces.util.XMLAttributesImpl.setNonNormalizedValue(Unknown Source)
at org.cyberneko.html.HTMLTagBalancer$Info.<init>(HTMLTagBalancer.java:1350)
at org.cyberneko.html.HTMLTagBalancer.startElement(HTMLTagBalancer.java:749)
at org.cyberneko.html.filters.DefaultFilter.startElement(DefaultFilter.java:136)
at org.cyberneko.html.filters.NamespaceBinder.startElement(NamespaceBinder.java:279)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanStartElement(HTMLScanner.java:2760)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
Duplicate attributes should be handled as HTML parsing errors without causing an unchecked exception.
The parser should recover or report a controlled parsing error instead of throwing ArrayIndexOutOfBoundsException.
| 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 | Not reproduced |
| 1.9.21 | 2.10.0 | Not reproduced |
| 1.9.21 | 2.11.0 | Not reproduced |
| 1.9.22 | 2.10.0 | Reproduced |
| 1.9.22 | 2.11.0 | Reproduced |
Among the tested combinations, NekoHTML 1.9.22 is the only confirmed affected release.
The constructor of HTMLTagBalancer.Info copies attributes into a new XMLAttributesImpl instance.
It calls addAttribute() but incorrectly uses the original loop index when updating attribute metadata.
When a duplicate attribute is encountered, Xerces updates an existing attribute entry instead of appending a new one.
As a result, the original source index can exceed the valid index range of the destination attribute array.
For the minimal reproducer, the fifth attribute accesses index 4 of an array with capacity 4, triggering the exception.
An attacker who can supply HTML content to an application using NekoHTML 1.9.22 may trigger an uncaught runtime exception during parsing.
This may cause denial of service in applications that do not properly handle unchecked exceptions.
The current proof of concept demonstrates termination of an individual parsing operation. JVM termination, persistent service unavailability, and resource exhaustion have not been established.
Use the index returned by addAttribute() instead of the original loop index:
int idx = newattrs.addAttribute(aqname, type, value);
newattrs.setNonNormalizedValue(idx, nonNormalizedValue);
newattrs.setSpecified(idx, specified);
The parser should also handle duplicate attributes consistently with HTML error-recovery rules.
The defect was discovered during coverage-guided differential fuzzing of Java HTML parsers and independently reproduced using the standalone Java program above.
This ticket replaces Bug #171 because the original report contained malformed code formatting. Both reports describe the same underlying defect.
Related report: https://sourceforge.net/p/nekohtml/bugs/171/