diff --git a/Autoupdate/SUBinaryDeltaCommon.h b/Autoupdate/SUBinaryDeltaCommon.h index 94f87e0a..0bbbd7a2 100644 --- a/Autoupdate/SUBinaryDeltaCommon.h +++ b/Autoupdate/SUBinaryDeltaCommon.h @@ -31,6 +31,9 @@ #define MAJOR_VERSION_IS_AT_LEAST(actualMajor, expectedMajor) (actualMajor >= expectedMajor) +// Relative path of custom icon data that may be set on a bundle via a resource fork +#define CUSTOM_ICON_PATH @"/Icon\r" + // Changes that break backwards compatibility will have different major versions // Changes that affect creating but not applying patches will have different minor versions typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion) diff --git a/Autoupdate/SUBinaryDeltaCommon.m b/Autoupdate/SUBinaryDeltaCommon.m index 533b18b1..05a95105 100644 --- a/Autoupdate/SUBinaryDeltaCommon.m +++ b/Autoupdate/SUBinaryDeltaCommon.m @@ -256,8 +256,11 @@ BOOL getRawHashOfTreeAndFileTablesWithVersion(unsigned char *hashBuffer, NSStrin continue; NSString *relativePath = pathRelativeToDirectory(normalizedPath, stringWithFileSystemRepresentation(ent->fts_path)); - if (relativePath.length == 0) + + // Ignore icon resource fork data + if (relativePath.length == 0 || [relativePath isEqualToString:CUSTOM_ICON_PATH]) { continue; + } unsigned char fileHash[CC_SHA1_DIGEST_LENGTH]; if (!_hashOfFileContents(fileHash, ent, tempBuffer, tempBufferSize)) { diff --git a/Autoupdate/SUBinaryDeltaCreate.m b/Autoupdate/SUBinaryDeltaCreate.m index 1a15bc61..4be9f713 100644 --- a/Autoupdate/SUBinaryDeltaCreate.m +++ b/Autoupdate/SUBinaryDeltaCreate.m @@ -440,6 +440,16 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF if (![key length]) { continue; } + + if ([key isEqualToString:CUSTOM_ICON_PATH]) { + if (verbose) { + fprintf(stderr, "\n"); + } + if (error != NULL) { + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Diffing bundles with a custom icon set via a resource fork is not supported. Detected presence of %@", @(ent->fts_path)] }]; + } + return NO; + } NSDictionary *info = infoForFile(ent); if (!info) { @@ -531,6 +541,16 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF if (![key length]) { continue; } + + if ([key isEqualToString:CUSTOM_ICON_PATH]) { + if (verbose) { + fprintf(stderr, "\n"); + } + if (error != NULL) { + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Diffing bundles with a custom icon set via a resource fork is not supported. Detected presence of %@", @(ent->fts_path)] }]; + } + return NO; + } NSDictionary *info = infoForFile(ent); if (!info) { diff --git a/Tests/SUBinaryDeltaTest.m b/Tests/SUBinaryDeltaTest.m index eff1f977..bbd759b9 100644 --- a/Tests/SUBinaryDeltaTest.m +++ b/Tests/SUBinaryDeltaTest.m @@ -1729,4 +1729,58 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec XCTAssertFalse(success); } +- (void)testCreatingPatchWithCustomIconInBeforeTree +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) { + NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"]; + NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]); + XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]); + + NSImage *iconImage = [NSImage imageNamed:NSImageNameAdvanced]; + XCTAssertNotNil(iconImage); + + BOOL setIcon = [[NSWorkspace sharedWorkspace] setIcon:iconImage forFile:sourceDirectory options:0]; + XCTAssertTrue(setIcon); + } afterDiffHandler:nil afterPatchHandler:nil]; + XCTAssertFalse(success); +} + +- (void)testCreatingPatchWithCustomIconInAfterTree +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) { + NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"]; + NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]); + XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]); + + NSImage *iconImage = [NSImage imageNamed:NSImageNameAdvanced]; + XCTAssertNotNil(iconImage); + + BOOL setIcon = [[NSWorkspace sharedWorkspace] setIcon:iconImage forFile:destinationDirectory options:0]; + XCTAssertTrue(setIcon); + } afterDiffHandler:nil afterPatchHandler:nil]; + XCTAssertFalse(success); +} + +- (void)testApplyingPatchAfterSettingCustomIcon +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) { + NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"]; + NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]); + XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]); + } afterDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *__unused destinationDirectory) { + NSImage *iconImage = [NSImage imageNamed:NSImageNameAdvanced]; + XCTAssertNotNil(iconImage); + + BOOL setIcon = [[NSWorkspace sharedWorkspace] setIcon:iconImage forFile:sourceDirectory options:0]; + XCTAssertTrue(setIcon); + } afterPatchHandler:nil]; + XCTAssertTrue(success); +} + @end diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index d9beccd2..82700375 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -47,7 +47,6 @@ [super setUp]; NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]]; - NSString *unitTestBundleIdentifier = unitTestBundle.bundleIdentifier; NSString *zippedAppURL = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"]; SUFileManager *fileManager = [[SUFileManager alloc] init];