[PATCH v2] Support compressed debug sections larger than 4 GiB
Alan Modra
amodra@gmail.com
Sun Jun 1 03:54:31 GMT 2025
On Sat, May 31, 2025 at 09:16:34PM +0900, Rui Ueyama wrote:
> From: Rui Ueyama <rui314@gmail.com>
>
> z_stream's avail_in and avail_out are defined as "unsigned int", so it
> cannot decode an entire compressed stream in one pass if the stream is
> larger than 4 GiB. The simplest solution to this problem is to use zlib's
> convenient uncompress2() function, which handles the details for us.
>
> Signed-off-by: Rui Ueyama <rui314@gmail.com>
Thanks, applied. I'm going to make the following change, which is
really just fussing.
Some 64-bit compilers have a 32-bit long, which could result in an
endless loop if uncompressed_size is larger than 4G.
diff --git a/bfd/compress.c b/bfd/compress.c
index b693204a3ea..4f92455dbd6 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -521,8 +521,10 @@ decompress_contents (bool is_zstd, bfd_byte *compressed_buffer,
buffers concatenated together, so we uncompress in a loop. */
do
{
- uLongf dst_len = uncompressed_size;
- uLong src_len = compressed_size;
+ uLongf dst_len = (uncompressed_size > ULONG_MAX ? ULONG_MAX
+ : uncompressed_size);
+ uLong src_len = (compressed_size > ULONG_MAX ? ULONG_MAX
+ : compressed_size);
int rc = uncompress2 ((Bytef *) uncompressed_buffer, &dst_len,
(Bytef *) compressed_buffer, &src_len);
if (rc != Z_OK)
--
Alan Modra
More information about the Binutils
mailing list