Skip to content

Commit ba829a4

Browse files
committed
Check for negative lengths in crc32_combine functions.
Though zlib.h says that len2 must be non-negative, this avoids the possibility of an accidental infinite loop.
1 parent 570720b commit ba829a4

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

crc32.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf,
10191019

10201020
/* ========================================================================= */
10211021
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) {
1022+
if (len2 < 0)
1023+
return 0;
10221024
#ifdef DYNAMIC_CRC_TABLE
10231025
once(&made, make_crc_table);
10241026
#endif /* DYNAMIC_CRC_TABLE */
@@ -1032,6 +1034,8 @@ uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) {
10321034

10331035
/* ========================================================================= */
10341036
uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) {
1037+
if (len2 < 0)
1038+
return 0;
10351039
#ifdef DYNAMIC_CRC_TABLE
10361040
once(&made, make_crc_table);
10371041
#endif /* DYNAMIC_CRC_TABLE */

zlib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,14 +1848,14 @@ ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
18481848
seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
18491849
calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
18501850
check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1851-
len2. len2 must be non-negative.
1851+
len2. len2 must be non-negative, otherwise zero is returned.
18521852
*/
18531853

18541854
/*
18551855
ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2);
18561856
18571857
Return the operator corresponding to length len2, to be used with
1858-
crc32_combine_op(). len2 must be non-negative.
1858+
crc32_combine_op(). len2 must be non-negative, otherwise zero is returned.
18591859
*/
18601860

18611861
ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);

0 commit comments

Comments
 (0)