Skip to content

Commit ec3df00

Browse files
committed
Correct incorrect inputs provided to the CRC functions.
The previous releases of zlib were not sensitive to incorrect CRC inputs with bits set above the low 32. This commit restores that behavior, so that applications with such bugs will continue to operate as before.
1 parent ce12773 commit ec3df00

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crc32.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
630630
#endif /* DYNAMIC_CRC_TABLE */
631631

632632
/* Pre-condition the CRC */
633-
crc ^= 0xffffffff;
633+
crc = (~crc) & 0xffffffff;
634634

635635
/* Compute the CRC up to a word boundary. */
636636
while (len && ((z_size_t)buf & 7) != 0) {
@@ -749,7 +749,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
749749
#endif /* DYNAMIC_CRC_TABLE */
750750

751751
/* Pre-condition the CRC */
752-
crc ^= 0xffffffff;
752+
crc = (~crc) & 0xffffffff;
753753

754754
#ifdef W
755755

@@ -1077,7 +1077,7 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
10771077
#ifdef DYNAMIC_CRC_TABLE
10781078
once(&made, make_crc_table);
10791079
#endif /* DYNAMIC_CRC_TABLE */
1080-
return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;
1080+
return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
10811081
}
10821082

10831083
/* ========================================================================= */
@@ -1112,5 +1112,5 @@ uLong crc32_combine_op(crc1, crc2, op)
11121112
uLong crc2;
11131113
uLong op;
11141114
{
1115-
return multmodp(op, crc1) ^ crc2;
1115+
return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
11161116
}

0 commit comments

Comments
 (0)