Skip to content

Close the .xsb stream when XsbDumper fails part-way through a file - #109

Merged
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:leak-xsbdumper-index
Sep 7, 2026
Merged

Close the .xsb stream when XsbDumper fails part-way through a file#109
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:leak-xsbdumper-index

Conversation

@pjfanning

Copy link
Copy Markdown
Member

XsbDumper owns the stream it is handed — dumpAll() closes it through readEnd() on the way out. But every read goes through error(), which throws IllegalStateException, so a truncated or corrupt .xsb aborts the dump with the stream still open.

That matters for the bulk entry points: dump(File) recurses over a whole directory tree opening a stream per .xsb, and dumpZip's try-with-resources catches only IOException, so an IllegalStateException from one bad entry escapes with that entry's stream leaked.

The dispatch now runs in a try/finally so readEnd() always runs. readEnd() gains a null guard because dumpIndexData() already calls it on its own success path — the same guard XsbReader.readEnd() has.

Added XsbDumperStreamTest, covering index, type and pointer files truncated after the header. All three fail on trunk and pass with this change.

🤖 Generated with Claude Code

XsbDumper owns the stream it is handed - dumpAll() closes it via readEnd() on
the way out. But every read goes through error(), which throws
IllegalStateException, so a truncated or corrupt .xsb aborts the dump with the
stream still open.

That matters for the directory and jar walks: dump(File) recurses over a whole
tree, and dumpZip's try-with-resources catches only IOException, so an
IllegalStateException from one bad entry escapes with that entry's stream
leaked.

Run the dispatch in a try/finally so readEnd() always runs, and null-guard
readEnd() since dumpIndexData() already calls it on its own success path.

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