Skip to content

Fix leftover output files and file handle leak when extraction fails#190

Merged
alek-prykhodko merged 2 commits into
masterfrom
fix/unarchiver-leftover-file-on-extraction-error
Jun 5, 2026
Merged

Fix leftover output files and file handle leak when extraction fails#190
alek-prykhodko merged 2 commits into
masterfrom
fix/unarchiver-leftover-file-on-extraction-error

Conversation

@alek-prykhodko
Copy link
Copy Markdown
Member

Summary

When file or resource fork extraction fails (due to a wrong password, cancellation, etc.) the output file created before extraction started was left on disk as empty or partial.
Additionally, a failed AppleDouble header write in _extractResourceForkEntryWithDictionary:asAppleDoubleFile: returned early without calling [fh close], leaking the file handle.

Changes

  • _extractFileEntryWithDictionary:as: — remove the output file on any non-zero error after [fh close];
  • _extractResourceForkEntryWithDictionary:asAppleDoubleFile: — unify the error path so [fh close] always runs, and remove the output file on any non-zero error.

P.S. Both fixes removes files for XADBreakError as well — cancellation is checked per 256KB chunk inside the read loop, so the file is partial in most cases at that point.

@alek-prykhodko alek-prykhodko self-assigned this Jun 2, 2026
@alek-prykhodko alek-prykhodko requested a review from Copilot June 2, 2026 12:44
@alek-prykhodko alek-prykhodko changed the title Fix leftover output files and leaked file handle on extraction failure Fix leftover output files and file handle leak when extraction fails Jun 2, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves extraction failure handling in XADUnarchiver by ensuring partially created output files are cleaned up and a file-handle leak is avoided when AppleDouble header writing fails.

Changes:

  • Delete the destination file after extraction when _extractFileEntryWithDictionary:as: returns a non-zero XADError.
  • Refactor _extractResourceForkEntryWithDictionary:asAppleDoubleFile: to consolidate error handling so the file handle is always closed.
  • Delete the AppleDouble output file on any non-zero XADError from header writing or resource-fork extraction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread XADUnarchiver.m
Comment thread XADUnarchiver.m
Copy link
Copy Markdown
Contributor

@PaulTaykalo PaulTaykalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix removes leftover output files and a file-handle leak when extraction fails. Author shipped XADMasterTests/Stuffit/StuffitTests.m::testExtractionWithWrongPasswordDoesNotLeaveFilesOnDisk covering the primary path with the 1234567.sit.bin fixture. The resource-fork (AppleDouble) error path is unchanged in behavior but untested; suggested follow-up, not blocking.

@alek-prykhodko alek-prykhodko merged commit 38f2c0e into master Jun 5, 2026
4 checks passed
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.

3 participants