Close the .xsb stream when XsbDumper fails part-way through a file - #109
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
XsbDumperowns the stream it is handed —dumpAll()closes it throughreadEnd()on the way out. But every read goes througherror(), which throwsIllegalStateException, so a truncated or corrupt.xsbaborts 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, anddumpZip's try-with-resources catches onlyIOException, so anIllegalStateExceptionfrom one bad entry escapes with that entry's stream leaked.The dispatch now runs in a
try/finallysoreadEnd()always runs.readEnd()gains a null guard becausedumpIndexData()already calls it on its own success path — the same guardXsbReader.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