diff options
author | Hans Wennborg <hans@chromium.org> | 2020-09-10 11:00:28 +0000 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2020-09-10 04:04:07 -0700 |
commit | f8517bd62931d7adb9bcefb0cbe3c2ca5cd8862c (patch) | |
tree | a462d253cb35f7800e68ab18b8db06de7fadb543 /deflate.c | |
parent | 898c6c0dd91fa0efb38a10949f76102e42cc47f0 (diff) | |
download | zlib-f8517bd62931d7adb9bcefb0cbe3c2ca5cd8862c.tar.gz |
[zlib] Adjust the scan[2]==match[2] assert for CRC hashing
When using CRC hashing, that assert doesn't hold, but a weaker variant
does.
Also disallow compiling with FASTEST defined, because I don't think
that longest_match variant would be safe with CRC hashing. It doesn't
guarantee that the fourth of the hashed bytes will be compared.
Bug: 1113596
Change-Id: I20ede29835b9c6b4bdc09fc1836864ffa2b10a97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401023
Commit-Queue: Hans Wennborg <hans@chromium.org>
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805690}
GitOrigin-RevId: 6d189bdd1c456fe0db3042b1ef3507ee96a0ff15
Diffstat (limited to 'deflate.c')
-rw-r--r-- | deflate.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -60,6 +60,11 @@ #include "crc32_simd.h" #endif +#ifdef FASTEST +/* See http://crbug.com/1113596 */ +#error "FASTEST is not supported in Chromium's zlib." +#endif + const char deflate_copyright[] = " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; /* @@ -1345,7 +1350,16 @@ local uInt longest_match(s, cur_match) * necessary to put more guard bytes at the end of the window, or * to check more often for insufficient lookahead. */ - Assert(scan[2] == match[2], "scan[2]?"); + if (!x86_cpu_enable_simd && !arm_cpu_enable_crc32) { + Assert(scan[2] == match[2], "scan[2]?"); + } else { + /* When using CRC hashing, scan[2] and match[2] may mismatch, but in + * that case at least one of the other hashed bytes will mismatch + * also. Bytes 0 and 1 were already checked above, and we know there + * are at least four bytes to check otherwise the mismatch would have + * been found by the scan_end comparison above, so: */ + Assert(scan[2] == match[2] || scan[3] != match[3], "scan[2]??"); + } scan++, match++; do { } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && @@ -1376,7 +1390,16 @@ local uInt longest_match(s, cur_match) * the hash keys are equal and that HASH_BITS >= 8. */ scan += 2, match++; - Assert(*scan == *match, "match[2]?"); + if (!x86_cpu_enable_simd && !arm_cpu_enable_crc32) { + Assert(*scan == *match, "match[2]?"); + } else { + /* When using CRC hashing, scan[2] and match[2] may mismatch, but in + * that case at least one of the other hashed bytes will mismatch + * also. Bytes 0 and 1 were already checked above, and we know there + * are at least four bytes to check otherwise the mismatch would have + * been found by the scan_end comparison above, so: */ + Assert(*scan == *match || scan[1] != match[1], "match[2]??"); + } /* We check for insufficient lookahead only every 8th comparison; * the 256th check will be made at strstart+258. |