[PATCH v2 1/3] bfd: fix reading compressed debug sections of pei-* images

Jan Beulich jbeulich@suse.com
Fri Nov 27 10:14:54 GMT 2026


On 26.11.2026 09:51, Tobias Deiminger wrote:
> Since 0921b99dafd5 ("PR 33033, Support compressed debug sections larger
> than 4 GiB"), compressed debug sections of pei-* images can no longer be
> read. For example:
> 
>  $ x86_64-w64-mingw32-gcc -g -o testprog testprog.c
>  $ objcopy --compress-debug-sections testprog.exe testprog_z.exe
>  $ gdb --batch -ex "break fn" -ex "info line fn" testprog_z.exe
>  warning: Can't read data for section '.zdebug_info' in file '/.../testprog_z.exe'
>  ...
>  No line number information available for address 0x140001490 <fn>
> 
> It worked prior to 0921b99dafd5, because padding that generally exists
> after zlib streams in compressed PE image sections was tolerated during
> decompression. 0921b99dafd5 turned padding into an error condition, most
> likely unintentionally, and decompression has failed since then.
> 
> The padding is an expected consequence of PE having no section field
> that could communicate the compressed size. See PR 18087 for discussion
> and withdrawn alternatives.
> 
> Fix it by restoring support for padding after compressed streams, and
> additionally sanitize decompression by allowing only zero padding, and
> by allowing it only for non-ELF files.
> 
> Signed-off-by: Tobias Deiminger <tobias.deiminger@linutronix.de>

This is okay, yet I wonder ...

> --- a/bfd/compress.c
> +++ b/bfd/compress.c
> @@ -525,7 +525,8 @@ static bool
>  decompress_contents (bool is_zstd, bfd_byte *compressed_buffer,
>  		     bfd_size_type compressed_size,
>  		     bfd_byte *uncompressed_buffer,
> -		     bfd_size_type uncompressed_size)
> +		     bfd_size_type uncompressed_size,
> +		     bool allow_padding)
>  {
>    if (is_zstd)
>      {
> @@ -552,7 +553,21 @@ decompress_contents (bool is_zstd, bfd_byte *compressed_buffer,
>        compressed_size -= src_len;
>      }
>    while (compressed_size > 0 && uncompressed_size > 0);
> -  return compressed_size == 0 && uncompressed_size == 0;

... why this line needs deleting. Can't we keep it, doing ...

> +
> +  if (allow_padding)
> +    {
> +      while (compressed_size > 0)
> +	{
> +	  if (*compressed_buffer != 0)
> +	    return false;
> +	  compressed_buffer++;
> +	  compressed_size--;
> +	}
> +    }
> +  else if (compressed_size > 0)
> +    return false;
> +
> +  return uncompressed_size == 0;
>  }

... this a little differently:

  if (allow_padding)
    {
      while (compressed_size > 0)
	{
	  if (*compressed_buffer != 0)
	    return false;
	  compressed_buffer++;
	  compressed_size--;
	}
    }

  return compressed_size == 0 && uncompressed_size == 0;

or even

  while (allow_padding && compressed_size > 0)
    {
      if (*compressed_buffer != 0)
	return false;
      compressed_buffer++;
      compressed_size--;
    }

  return compressed_size == 0 && uncompressed_size == 0;

(I'm considering to simply switch to one of these when committing.)

Jan


More information about the Binutils mailing list