mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Ignore custom icons set via resource forks in delta updates (#2114)
For creation, we will disallow creating delta updates if a custom resource fork icon data is found in either the old or app bundles. For applying, we will just ignore the icon data when performing hash verification and continue applying the patch.
This commit is contained in:
5 files changed
+81
-2
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user