Skip to content

Close the XsbReader when resolveHandle meets an unhandled file type - #108

Merged
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:leak-resolvehandle-filetype
Sep 7, 2026
Merged

Close the XsbReader when resolveHandle meets an unhandled file type#108
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:leak-resolvehandle-filetype

Conversation

@pjfanning

Copy link
Copy Markdown
Member

SchemaTypeSystemImpl.resolveHandle constructs an XsbReader — which opens the .xsb resource stream — and then dispatches on the file type it read. Every finishLoadingXxx() closes the reader in a finally, but the default: arm throws IllegalStateException without closing, leaking the stream.

That arm is reachable in practice: FILETYPE_SCHEMAPOINTER is a file type the compiler writes (savePointerFile) but this switch does not handle, as is any file type read out of a corrupt or crafted .xsb.

Added ResolveHandleFileTypeTest, which serves a well-formed pointer .xsb through a stub ResourceLoader and asserts the stream is closed. It fails on trunk and passes with this change.

🤖 Generated with Claude Code

SchemaTypeSystemImpl.resolveHandle opens an XsbReader, then dispatches on the
file type it finds. Each finishLoadingXxx() closes the reader in a finally, but
the default arm throws IllegalStateException without closing, leaking the
underlying .xsb stream.

The arm is reachable: FILETYPE_SCHEMAPOINTER is a file type the compiler
writes but this switch does not handle, as is any type read from a corrupt or
crafted .xsb.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pjfanning
pjfanning merged commit c8854bb into apache:trunk Sep 7, 2026
3 checks passed
@pjfanning
pjfanning deleted the leak-resolvehandle-filetype branch September 7, 2026 11:48
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