Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion XADMasterTests/Stuffit/StuffitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,39 @@ - (void)testArchiveCanBeExtractedWithMoreThan8CharactersInPassword

XCTAssertEqual(error, XADNoError, @"Error unarchiving: %@", [XADException describeXADError:error]);
XCTAssertFalse(_delegate.extractionFailed, @"Extraction failed: %@", [XADException describeXADError:_delegate.error]);


}

- (void)testExtractionWithWrongPasswordDoesNotLeaveFilesOnDisk
{
// Arrange
NSURL *fixtureURL = [[NSBundle bundleForClass:[XADStuffitTests class]]
URLForResource:@"1234567" withExtension:@"sit.bin" subdirectory:@"StuffitFixtures"];
XCTAssertNotNil(fixtureURL, @"Fixture file not found");

XADError createError;
XADSimpleUnarchiver *unarchiver = [XADSimpleUnarchiver simpleUnarchiverForPath:fixtureURL.path
error:&createError];
XCTAssertEqual(createError, XADNoError);
XCTAssertNotNil(unarchiver);

[unarchiver setDelegate:self.delegate];
[unarchiver setPassword:@"wrongpassword"];
[unarchiver setDestination:self.tempDirURL.path];

XADError parseError = [unarchiver parse];
XCTAssertEqual(parseError, XADNoError, @"Parse should succeed regardless of password");

// Act
[unarchiver unarchive];

// Assert — wrong password was actually the failure cause
XCTAssertTrue(self.delegate.extractionFailed);
XCTAssertEqual(self.delegate.error, XADPasswordError);

// Assert — no leftover files on disk
NSArray *items = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.tempDirURL.path error:nil];
XCTAssertEqualObjects(items, @[], @"Leftover files found after failed extraction: %@", items);
}

@end
31 changes: 24 additions & 7 deletions XADUnarchiver.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ -(XADError)_extractFileEntryWithDictionary:(NSDictionary *)dict as:(NSString *)d

[fh close];

// Remove the output file on any failure. This includes XADBreakError, which in
// most cases produces a partial file (cancellation is checked per 256KB chunk).
if(err!=XADNoError)
{
[XADPlatform removeItemAtPath:destpath];
}
Comment thread
alek-prykhodko marked this conversation as resolved.

return err;
}

Expand Down Expand Up @@ -498,20 +505,30 @@ -(XADError)_extractResourceForkEntryWithDictionary:(NSDictionary *)dict asAppleD

NSDictionary *extattrs=[parser extendedAttributesForDictionary:dict];

XADError error=XADNoError;
@try
{
// TODO: Should this function handle exceptions itself?
[XADAppleDouble writeAppleDoubleHeaderToHandle:fh resourceForkSize:(int)ressize
extendedAttributes:extattrs];
[XADAppleDouble writeAppleDoubleHeaderToHandle:fh
resourceForkSize:(int)ressize
extendedAttributes:extattrs];
if(ressize)
{
error=[self runExtractorWithDictionary:dict outputHandle:fh];
}
} @catch(id e) {
error=[XADException parseException:e];
}
@catch(id e) { return [XADException parseException:e]; }

// Write resource fork.
XADError error=XADNoError;
if(ressize) error=[self runExtractorWithDictionary:dict outputHandle:fh];

[fh close];

// Remove the output file on any failure. This includes XADBreakError, which in
// most cases produces a partial file (cancellation is checked per 256KB chunk).
if(error!=XADNoError)
{
[XADPlatform removeItemAtPath:destpath];
}
Comment thread
alek-prykhodko marked this conversation as resolved.

return error;
}

Expand Down
Loading