[PATCH v2] Support compressed debug sections larger than 4 GiB
Rui Ueyama
ruiu@cs.stanford.edu
Mon Jun 2 12:26:32 GMT 2025
On Sun, Jun 1, 2025 at 12:54 PM Alan Modra <amodra@gmail.com> wrote:
>
> 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)
uncompress2 is not a streaming API and doesn't have a context, so I
don't think it can decode 4 GiB chunks one at a time. We need to
decode the entire zlib-compressed buffer in a single call. So, maybe
we should report an error if compressed_size and/or uncompressed_size
exceeds 4 GiB and sizeof(long) is 4?
More information about the Binutils
mailing list