Skip to content

Commit 738767b

Browse files
committed
decompress_contents: fuss over 32-bit long
Some 64-bit compilers have a 32-bit long, which could result in an endless loop if uncompressed_size is larger than 4G.
1 parent 0921b99 commit 738767b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

bfd/compress.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,10 @@ decompress_contents (bool is_zstd, bfd_byte *compressed_buffer,
521521
buffers concatenated together, so we uncompress in a loop. */
522522
do
523523
{
524-
uLongf dst_len = uncompressed_size;
525-
uLong src_len = compressed_size;
524+
uLongf dst_len = (uncompressed_size > ULONG_MAX ? ULONG_MAX
525+
: uncompressed_size);
526+
uLong src_len = (compressed_size > ULONG_MAX ? ULONG_MAX
527+
: compressed_size);
526528
int rc = uncompress2 ((Bytef *) uncompressed_buffer, &dst_len,
527529
(Bytef *) compressed_buffer, &src_len);
528530
if (rc != Z_OK)

0 commit comments

Comments
 (0)