Skip to content

reject negative annotation counts in XsbReader index loader#89

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:xsb-annotation-count-guard
Open

reject negative annotation counts in XsbReader index loader#89
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:xsb-annotation-count-guard

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 23, 2026

Copy link
Copy Markdown

Loading a compiled schema whose annotation section carries a crafted count:

java.lang.NegativeArraySizeException: -2
    at org.apache.xmlbeans.impl.schema.XsbReader.readAnnotation(XsbReader.java:386)

readAnnotation and readAnnotations size three arrays and an ArrayList straight from a signed readInt() count in the .xsb stream. Only -1 is handled, the null-annotation marker. Any other negative count from a corrupt or crafted index throws NegativeArraySizeException here, and new ArrayList<>(n) in readAnnotations throws IllegalArgumentException. initFromHeader reads the annotations inside a plain try/finally and the SchemaTypeSystemImpl constructor only logs and rethrows, so this leaves the loader as a raw runtime exception rather than SchemaTypeLoaderException.

Found while walking the readInt sites in the class. Every other count reads through the unsigned readShort() helper and cannot go negative, these four annotation counts were the only signed ones. Guarded all four with the UNRECOGNIZED_INDEX_ENTRY check already used by stringForCode and readFrom. Valid files parse unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant