diff --git a/Autoupdate/SUBinaryDeltaCommon.m b/Autoupdate/SUBinaryDeltaCommon.m index 40bea730..c6e30bec 100644 --- a/Autoupdate/SUBinaryDeltaCommon.m +++ b/Autoupdate/SUBinaryDeltaCommon.m @@ -113,11 +113,11 @@ uint16_t latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersio case SUBinaryDeltaMajorVersion1: return 2; case SUBinaryDeltaMajorVersion2: - return 4; + return 5; case SUBinaryDeltaMajorVersion3: - return 1; + return 2; case SUBinaryDeltaMajorVersion4: - return 0; + return 1; } return 0; } diff --git a/Vendor/bsdiff/bsdiff.c b/Vendor/bsdiff/bsdiff.c index 8dfb3c20..610c5d5e 100644 --- a/Vendor/bsdiff/bsdiff.c +++ b/Vendor/bsdiff/bsdiff.c @@ -84,7 +84,9 @@ static off_t search(off_t *I, u_char *old, off_t oldsize, } x = st + (en - st)/2; - if (memcmp(old + I[x], new, (size_t)(MIN(oldsize - I[x], newsize))) < 0) { + /* Modification ported from ChromiumOS project: + * https://chromium.googlesource.com/chromiumos/third_party/bsdiff/+/58146f74abd6b1b69693943195f37f4ac6a6acef%5E%21/#F0 */ + if (memcmp(old + I[x], new, (size_t)(MIN(oldsize - I[x], newsize))) <= 0) { return search(I, old, oldsize, new, newsize, x, en, pos); } else { return search(I, old, oldsize, new, newsize, st, x, pos); @@ -212,8 +214,18 @@ int bsdiff(int argc, char *argv[]) lastoffset = 0; while (scan < newsize) { oldscore = 0; - + /* Modification ported from ChromiumOS project: + * https://chromium.googlesource.com/chromiumos/third_party/bsdiff/+/a055996c743add7a9558839276fd1e4994d16bd3%5E%21/#F0 */ + /* If we come across a large block of data that only differs + * by less than 8 bytes, this loop will take a long time to + * go past that block of data. We need to track the number of + * times we're stuck in the block and break out of it. */ + int num_less_than_eight = 0; + off_t prev_len, prev_oldscore, prev_pos; for (scsc = scan += len; scan < newsize; scan++) { + prev_len = len; + prev_oldscore = oldscore; + prev_pos = pos; /* 'oldscore' is the number of characters that match between the * substrings 'old[lastoffset + scan:lastoffset + scsc]' and * 'new[scan:scsc]'. */ @@ -240,6 +252,19 @@ int bsdiff(int argc, char *argv[]) if ((scan + lastoffset < oldsize) && (old[scan + lastoffset] == new[scan])) oldscore--; + + /* Modification ported from ChromiumOS project: + * https://chromium.googlesource.com/chromiumos/third_party/bsdiff/+/426e4aa1cbeb3c8a73002047d7a796ca8e5e17d4%5E%21/#F0 */ + const off_t fuzz = 8; + if (prev_len - fuzz <= len && len <= prev_len && + prev_oldscore - fuzz <= oldscore && + oldscore <= prev_oldscore && + prev_pos <= pos && pos <= prev_pos + fuzz && + oldscore <= len && len <= oldscore + fuzz) + ++num_less_than_eight; + else + num_less_than_eight=0; + if (num_less_than_eight > 100) break; } /* Skip this section if we found an exact match that would be