Skip to content

reject negative UTF length in LongUTFDataInputStream.readLongUTF - #93

Merged
pjfanning merged 1 commit into
apache:trunkfrom
aizu-m:longutf-negative-length
Aug 20, 2026
Merged

reject negative UTF length in LongUTFDataInputStream.readLongUTF#93
pjfanning merged 1 commit into
apache:trunkfrom
aizu-m:longutf-negative-length

Conversation

@aizu-m

@aizu-m aizu-m commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

readUnsignedShortOrInt falls back to a signed readInt for the 0xfffe marker so the modified-UTF length can arrive negative, and it flows straight into new StringBuilder(utfLen/2) which throws NegativeArraySizeException out of StringPool.readFrom and crackPointer (both catch only IOException) instead of the SchemaTypeLoaderException the loader is contracted to use; rejecting a negative length as a UTFDataFormatException matches the malformed cases already handled in this method and lets the existing IOException catch wrap it.

@pjfanning

Copy link
Copy Markdown
Member

these are not public APIs - these changes cause performance degradations - do we really need them? - if it isn't clear that the internals of XMLBeans are for internal use, we can improve the docs

@aizu-m

aizu-m commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Fair point, it's an internal class and the only realistic trigger is a corrupt or tampered .xsb on the classpath. I hit it while fuzzing the string pool loader, same path as #88 and #89. Cost-wise it's one int compare per pooled string at schema load, nothing on the parse or save paths, so I don't think it's measurable, but I take the point that each of these adds up. If you'd rather not carry it, I'm fine with this being closed.

@pjfanning
pjfanning merged commit e27f97b into apache:trunk Aug 20, 2026
3 checks passed
@pjfanning

Copy link
Copy Markdown
Member

Ok. I'll merge this. I'm not worried about hacked xsb files - if you can hack them, then you can hack classes.
I still don't regard this as a big improvement in this lib and it fights against a basically non-existent problem.
I don't care what the fuzzer is doing, it is generating garbage.

@aizu-m

aizu-m commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Understood, and thanks for merging it.

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.

2 participants