diff options
| author | Mark Adler <git@madler.net> | 2025-12-21 18:17:56 -0800 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-01-05 15:03:04 -0600 |
| commit | ba829a458576d1ff0f26fc7230c6de816d1f6a77 (patch) | |
| tree | b955e6951991dbb4aed9c556a6f2b28645ca95fb | |
| parent | 570720b0c24f9686c33f35a1b3165c1f568b96be (diff) | |
| download | zlib-ba829a458576d1ff0f26fc7230c6de816d1f6a77.tar.gz zlib-ba829a458576d1ff0f26fc7230c6de816d1f6a77.tar.bz2 zlib-ba829a458576d1ff0f26fc7230c6de816d1f6a77.zip | |
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.
| -rw-r--r-- | crc32.c | 4 | ||||
| -rw-r--r-- | zlib.h | 4 |
2 files changed, 6 insertions, 2 deletions
| @@ -1019,6 +1019,8 @@ unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, | |||
| 1019 | 1019 | ||
| 1020 | /* ========================================================================= */ | 1020 | /* ========================================================================= */ |
| 1021 | uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { | 1021 | uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { |
| 1022 | if (len2 < 0) | ||
| 1023 | return 0; | ||
| 1022 | #ifdef DYNAMIC_CRC_TABLE | 1024 | #ifdef DYNAMIC_CRC_TABLE |
| 1023 | once(&made, make_crc_table); | 1025 | once(&made, make_crc_table); |
| 1024 | #endif /* DYNAMIC_CRC_TABLE */ | 1026 | #endif /* DYNAMIC_CRC_TABLE */ |
| @@ -1032,6 +1034,8 @@ uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { | |||
| 1032 | 1034 | ||
| 1033 | /* ========================================================================= */ | 1035 | /* ========================================================================= */ |
| 1034 | uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { | 1036 | uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { |
| 1037 | if (len2 < 0) | ||
| 1038 | return 0; | ||
| 1035 | #ifdef DYNAMIC_CRC_TABLE | 1039 | #ifdef DYNAMIC_CRC_TABLE |
| 1036 | once(&made, make_crc_table); | 1040 | once(&made, make_crc_table); |
| 1037 | #endif /* DYNAMIC_CRC_TABLE */ | 1041 | #endif /* DYNAMIC_CRC_TABLE */ |
| @@ -1848,14 +1848,14 @@ ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); | |||
| 1848 | seq1 and seq2 with lengths len1 and len2, CRC-32 check values were | 1848 | seq1 and seq2 with lengths len1 and len2, CRC-32 check values were |
| 1849 | calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 | 1849 | calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 |
| 1850 | check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and | 1850 | 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. |
| 1852 | */ | 1852 | */ |
| 1853 | 1853 | ||
| 1854 | /* | 1854 | /* |
| 1855 | ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); | 1855 | ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); |
| 1856 | 1856 | ||
| 1857 | Return the operator corresponding to length len2, to be used with | 1857 | 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. |
| 1859 | */ | 1859 | */ |
| 1860 | 1860 | ||
| 1861 | ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); | 1861 | ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); |
