From 14c543ccb35fc8f6ae0abaf55f2edbcfb56602cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 27 Jan 2017 18:05:23 +0000 Subject: [PATCH 1/5] Test with non-ASCII names --- Tests/SUBinaryDeltaTest.m | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/SUBinaryDeltaTest.m b/Tests/SUBinaryDeltaTest.m index 7978fa5c..544be1ff 100644 --- a/Tests/SUBinaryDeltaTest.m +++ b/Tests/SUBinaryDeltaTest.m @@ -24,8 +24,8 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec - (void)testTemporaryDirectory { - NSString *tmp1 = temporaryDirectory(@"Sparkle"); - NSString *tmp2 = temporaryDirectory(@"Sparkle"); + NSString *tmp1 = temporaryDirectory(@"Sparklęエンジン"); + NSString *tmp2 = temporaryDirectory(@"Sparklęエンジン"); NSLog(@"Temporary directories: %@, %@", tmp1, tmp2); XCTAssertNotEqualObjects(tmp1, tmp2); XCTAssert(YES, @"Pass"); @@ -33,8 +33,8 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec - (void)testTemporaryFile { - NSString *tmp1 = temporaryFilename(@"Sparkle"); - NSString *tmp2 = temporaryFilename(@"Sparkle"); + NSString *tmp1 = temporaryFilename(@"Sparklęエンジン"); + NSString *tmp2 = temporaryFilename(@"Sparklęエンジン"); NSLog(@"Temporary files: %@, %@", tmp1, tmp2); XCTAssertNotEqualObjects(tmp1, tmp2); XCTAssert(YES, @"Pass"); @@ -42,12 +42,12 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec - (BOOL)createAndApplyPatchUsingVersion:(SUBinaryDeltaMajorVersion)majorVersion beforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler { - NSString *sourceDirectory = temporaryDirectory(@"Sparkle_temp1"); - NSString *destinationDirectory = temporaryDirectory(@"Sparkle_temp2"); - - NSString *diffFile = temporaryFilename(@"Sparkle_diff"); - NSString *patchDirectory = temporaryDirectory(@"Sparkle_patch"); - + NSString *sourceDirectory = temporaryDirectory(@"Spąrkle_temp1エンジン"); + NSString *destinationDirectory = temporaryDirectory(@"Spąrkle_temp2エンジン"); + + NSString *diffFile = temporaryFilename(@"Spąrkle_diffエンジン"); + NSString *patchDirectory = temporaryDirectory(@"Spąrkle_patchエンジン"); + XCTAssertNotNil(sourceDirectory); XCTAssertNotNil(destinationDirectory); XCTAssertNotNil(diffFile); @@ -120,9 +120,9 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec { [self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) { NSData *emptyData = [NSData data]; - NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"]; - NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"]; - + NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"AĄエンジン"]; + NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"AĄエンジン"]; + XCTAssertTrue([emptyData writeToFile:sourceFile atomically:YES]); XCTAssertTrue([emptyData writeToFile:destinationFile atomically:YES]); From 0a869e87bf88e53cc8f0f1c46629e98d7fe5220c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 27 Jan 2017 18:34:56 +0000 Subject: [PATCH 2/5] Make normalizedInstallationPathForHost also normalize Unicode --- Sparkle/SUInstaller.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 8a9d8f38..23d8c6e8 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -154,8 +154,10 @@ assert(bundle != nil); NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[bundle bundlePath] pathExtension]]]; - - return normalizedAppPath; + + // Roundtrip string through fileSystemRepresentation to ensure it uses filesystem's Unicode normalization + // rather than arbitrary Unicode form from Info.plist - #1017 + return [NSString stringWithUTF8String:[normalizedAppPath fileSystemRepresentation]]; } @end From ed16c5c2a08bc1db16c1f7261f90d3fc77013bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 27 Jan 2017 18:37:35 +0000 Subject: [PATCH 3/5] Use the same fileSystemRepresentation function for both parts of the path --- Sparkle/SUBinaryDeltaCommon.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index 42e9d6c0..9d10208e 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -163,6 +163,9 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion) CC_SHA1_CTX hashContext; CC_SHA1_Init(&hashContext); + // Ensure the path uses filesystem-specific Unicode normalization #1017 + NSString *normalizedPath = stringWithFileSystemRepresentation(pathBuffer); + FTSENT *ent = 0; while ((ent = fts_read(fts))) { if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) @@ -171,8 +174,8 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion) if (ent->fts_info == FTS_D && !MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) { continue; } - - NSString *relativePath = pathRelativeToDirectory(path, stringWithFileSystemRepresentation(ent->fts_path)); + + NSString *relativePath = pathRelativeToDirectory(normalizedPath, stringWithFileSystemRepresentation(ent->fts_path)); if (relativePath.length == 0) continue; From 21214e8623cdc3c064a5c9fdf5e31323a47c8767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Sat, 28 Jan 2017 11:08:53 +0000 Subject: [PATCH 4/5] Simplify minor delta version down to int + minor version bump --- Sparkle/SUBinaryDeltaApply.m | 6 +++--- Sparkle/SUBinaryDeltaCommon.h | 11 +---------- Sparkle/SUBinaryDeltaCommon.m | 8 ++++---- Sparkle/SUBinaryDeltaTool.m | 6 +++--- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Sparkle/SUBinaryDeltaApply.m b/Sparkle/SUBinaryDeltaApply.m index ea93b2be..a42bd0ee 100644 --- a/Sparkle/SUBinaryDeltaApply.m +++ b/Sparkle/SUBinaryDeltaApply.m @@ -39,7 +39,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi } SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION; - SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION; + int minorDiffVersion = 0; NSString *expectedBeforeHashv1 = nil; NSString *expectedAfterHashv1 = nil; @@ -62,8 +62,8 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi // available in version 2.0 or later xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value); if (value) - minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue]; - + minorDiffVersion = [@(value) intValue]; + // available in version 2.0 or later xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_KEY, &value); if (value) diff --git a/Sparkle/SUBinaryDeltaCommon.h b/Sparkle/SUBinaryDeltaCommon.h index 3e7db6c6..c1e80812 100644 --- a/Sparkle/SUBinaryDeltaCommon.h +++ b/Sparkle/SUBinaryDeltaCommon.h @@ -57,16 +57,7 @@ typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion) SUBeigeMajorVersion = 2 }; -// Only keep track of the latest minor version for each major version -typedef NS_ENUM(uint16_t, SUBinaryDeltaMinorVersion) -{ - SUAzureMinorVersion = 1, - SUBeigeMinorVersion = 1, -}; - #define FIRST_DELTA_DIFF_MAJOR_VERSION SUAzureMajorVersion -#define FIRST_DELTA_DIFF_MINOR_VERSION ((SUBinaryDeltaMinorVersion)0) - #define LATEST_DELTA_DIFF_MAJOR_VERSION SUBeigeMajorVersion extern int compareFiles(const FTSENT **a, const FTSENT **b); @@ -80,5 +71,5 @@ extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path); NSString *temporaryFilename(NSString *base); NSString *temporaryDirectory(NSString *base); NSString *stringWithFileSystemRepresentation(const char*); -SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion); +int latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion); #endif diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index 9d10208e..e396ed05 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -39,15 +39,15 @@ NSString *stringWithFileSystemRepresentation(const char *input) { return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:input length:strlen(input)]; } -SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion) +int latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion) { switch (majorVersion) { case SUAzureMajorVersion: - return SUAzureMinorVersion; + return 1; case SUBeigeMajorVersion: - return SUBeigeMinorVersion; + return 2; } - return (SUBinaryDeltaMinorVersion)0; + return 0; } NSString *temporaryFilename(NSString *base) diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index fae14ed1..573bf4aa 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -188,10 +188,10 @@ static BOOL runVersionCommand(NSString *programName, NSArray *args) fprintf(stderr, "Unable to open patch %s\n", [patchFile fileSystemRepresentation]); return NO; } - + SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION; - SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION; - + int minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION; + xar_subdoc_t subdoc; for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) { if (!strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY)) { From 67b1e08a4506b57ac8bf873694d4025b5c1d90b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Sat, 28 Jan 2017 11:16:45 +0000 Subject: [PATCH 5/5] Delta minor version fix --- Sparkle/SUBinaryDeltaCreate.m | 6 +++--- Sparkle/SUBinaryDeltaTool.m | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sparkle/SUBinaryDeltaCreate.m b/Sparkle/SUBinaryDeltaCreate.m index b0dfa3ef..c9a436b6 100644 --- a/Sparkle/SUBinaryDeltaCreate.m +++ b/Sparkle/SUBinaryDeltaCreate.m @@ -230,9 +230,9 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF assert(destination); assert(patchFile); assert(majorVersion >= FIRST_DELTA_DIFF_MAJOR_VERSION && majorVersion <= LATEST_DELTA_DIFF_MAJOR_VERSION); - - SUBinaryDeltaMinorVersion minorVersion = latestMinorVersionForMajorVersion(majorVersion); - + + int minorVersion = latestMinorVersionForMajorVersion(majorVersion); + NSMutableDictionary *originalTreeState = [NSMutableDictionary dictionary]; char pathBuffer[PATH_MAX] = {0}; diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index 573bf4aa..b130ec6a 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -190,7 +190,7 @@ static BOOL runVersionCommand(NSString *programName, NSArray *args) } SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION; - int minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION; + int minorDiffVersion = 0; xar_subdoc_t subdoc; for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) { @@ -205,7 +205,7 @@ static BOOL runVersionCommand(NSString *programName, NSArray *args) // available in version 2.0 or later xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value); if (value) - minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue]; + minorDiffVersion = [@(value) intValue]; } }