| Message ID | ao0kpuAp4iFRJAKQ@squeak.grove.modra.org |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0AA14BA7999 for <patchwork@sourceware.org>; Tue, 25 Aug 2026 05:14:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0AA14BA7999 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=tMTHHyCl X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by sourceware.org (Postfix) with ESMTPS id 5F03E4BA23E6 for <binutils@sourceware.org>; Tue, 25 Aug 2026 05:14:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F03E4BA23E6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F03E4BA23E6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787634859; cv=none; b=mMQDYpSxcB+F4VP0JT3hzgSk/WZA1JTVQnsql8aoBv+20q0Cr9/WXXsxQTRB8bxr2htNj8jXpaXuSfLfjk5ikXvsJEQD8B+hDwqZ10IgLCCtUgpLwZfXqXbMTyC1Mzc9V7XXbBwCilm4OOWHPL2fUgt14BK2JjaVy5UZrgz2a78= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787634859; c=relaxed/simple; bh=+EaEs0tHqREkTwhBBFvSI3gP1/YLxMuTyLTOH5eJKQ0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=wgWmU7fu958zUuLn4SgKRFd7HFN7Ul/18E+3EBQgALx2drRJdqQzJd7B2hNEaeolwl5QL1vcjDeKmBdtAroHKOttRIrp50WwQF+bZPIBlBLCpxtgLxPwXM039xHyAOuDDOyt0hpCmtMsfHeHUKxgTZ4A66PSnaGh7NN8AsorBDY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=tMTHHyCl DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F03E4BA23E6 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-383b4a3755fso4767847a91.3 for <binutils@sourceware.org>; Mon, 24 Aug 2026 22:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787634858; x=1788239658; darn=sourceware.org; h=content-disposition:content-type:mime-version:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=DLTLhPzG0hXHiawqodrRB2QeowVInU0VirtpNyaLJ5E=; b=tMTHHyClxnTGaTpOvm0xDaDmJYZJktA6Ky9EqFn0lZ8efXthF1GnS/3Yhov2T4WH38 qV3u0F3Yc53mrgKgDU48iJGr86Aducidxff0K520Ab5jbhdE3LjMzL//fqUNjMrjqOY/ 1RqUBUl6cZ8KqGe2DWMqvCGpotPtxA60IvDLfjNWI8Z5Tgy601ATCTqtMfZ+JfFhs1/a fB6igy7TlY+Jbw6wzgt1uJEziOug4aqFxXBDd1bAawQcjXPkEJbsC5wJzWNBj2en0RcP oOIEPcU025jpNC0/mTw3cndzjNq/hCSs8sJ7aHyAN6rlXjsUXPvwLtxklYC9jKCHkYxM yhFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787634858; x=1788239658; h=content-disposition:content-type:mime-version:message-id:subject:to :from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DLTLhPzG0hXHiawqodrRB2QeowVInU0VirtpNyaLJ5E=; b=Fvs4E+GhP9cswLufvsLBOvxxkHHDMWZ6t9p19WjG6SzFl97wz8QDrVOuPpNVM+yRyL KzR7Mo4IW1l1bNvDbskIWJOUfDaJH3o4YJxGq1ejXJPe35e69fNxozGwbJs+3KKAxIZ9 4CCDyllrLGdR/YwqM1D6C9H2fLvVhSaCBIj2Y4ouZPa4mn6kUM5pVQrwokC8jWPwmYG4 gvc0I8Hu1rtmFqlBKPGQ0KuSFMCDzp/HBneGI7yLO4D56U3LGlaI/3irTpaFG9tEpnHd vDF2Z6PjGsqr1LtdkAHUWlpzLmCiMiGjiFbUnAth3TwawkRiJ6anDnc5bQNJhH3jXa5I +TlA== X-Gm-Message-State: AFuF++nrof3/BF1Jo6YM8UFCt5hEhRywfgZ+BzJ2/qDvCr8sLLGO4+hT W7T7xbIoVArzmGeFhIh6BXQEPBvXvtX4YEsh1/K6yQAKIvan1gqkI9ImvZkrFA== X-Gm-Gg: AR+sD13kwb7vOvgSOCJB5ZYQVcZV3pq3UHHOr/b+8uHJ3gWxTopzNznW1Ej2LeacbZI kiOF7Tlq6Ac0+0WVjsxM/9Alf4Mc1PTqqEz5bZkX7CRgYo9lMWxCtyrRw7yz38tHNyo+Me4E6Pv a9IodHFLvmw3iqG276Mn15iGyMr3vZYBD3DmkNQGLQ7c+xbUHAkoXKLU2gBUb+6zEyZ0pv6zcdZ JS51p3aVWk0l8OhHRgWftaorwXenc1TwIYMbV1PG2FQmwrJf8J2OmZwQANiij3FOLMHBtxJndHe LEVL4JUoUSPwxmxbPD+AUz7fovk/MdMVX8ZggrT4w2f3SLQglis2l9YB3EjNgpkyujRt6dWuob3 3x8CAW64Nj0O7JRO6JHOUn9Jm5QmcMjYwRufwVMVPbZ0HeFAKDw2HjMHaN3GMUf0YHoHz3DYOum O9hpcqCUI4tsYup5bJu57uBGEuS+ZqAcLpX8cTefwvRvRMpo2+d7B/iNu3Ro3oBF0DG5UgYkbD8 jjGoAO8nCCvFdkN6wNqQWcTQhEZokKMM2ZpQG1M X-Received: by 2002:a17:90b:28ce:b0:38e:70d5:b12d with SMTP id 98e67ed59e1d1-396463997e2mr8682697a91.6.1787634858190; Mon, 24 Aug 2026 22:14:18 -0700 (PDT) Received: from squeak.grove.modra.org (58-96-106-158.ip4.superloop.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3965a55e658sm516309a91.3.2026.08.24.22.14.17 for <binutils@sourceware.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 22:14:17 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B16D71140BEA; Tue, 25 Aug 2026 14:44:14 +0930 (ACST) Date: Tue, 25 Aug 2026 14:44:14 +0930 From: Alan Modra <amodra@gmail.com> To: binutils@sourceware.org Subject: [RFC] PR 34481 arbitrary limit on decompressed size of .dwo files Message-ID: <ao0kpuAp4iFRJAKQ@squeak.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3029.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
[RFC] PR 34481 arbitrary limit on decompressed size of .dwo files
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_binutils_build--master-arm | warning | Skipped because it is an RFC |
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 | warning | Skipped because it is an RFC |
Commit Message
Alan Modra
Aug. 25, 2026, 5:14 a.m. UTC
PR34481 exposes a failure of a heuristic in bfd_section_size_insane dealing with compressed sections. The assumption there is that a compressed section would not be more than ten times the total file size. This of course is foolish since one highly compressed section can easily exceed ten times the total file size. However, it mostly worked for real object files. The claim in pr34481 is that the limit has been hit for .dwo files in a real C++ codebase. I don't find that claim unbelievable. While we could work around the .dwo problem with the following patch, I'm inclined to simply remove the whole "size / 10 > filesize" block. My reasoning is that this is anti-fuzzer code. If we allow a .dwo hole then the anti-fuzzer code may as well not be there. Fuzzers will soon find the hole. What do you all think? * section.c (bfd_section_size_insane): Do not attempt to limit .dwo section sizes.
Comments
On 25.08.2026 07:14, Alan Modra wrote: > PR34481 exposes a failure of a heuristic in bfd_section_size_insane > dealing with compressed sections. The assumption there is that a > compressed section would not be more than ten times the total file > size. This of course is foolish since one highly compressed section > can easily exceed ten times the total file size. However, it mostly > worked for real object files. The claim in pr34481 is that the limit > has been hit for .dwo files in a real C++ codebase. I don't find that > claim unbelievable. > > While we could work around the .dwo problem with the following patch, > I'm inclined to simply remove the whole "size / 10 > filesize" block. > > My reasoning is that this is anti-fuzzer code. If we allow a .dwo > hole then the anti-fuzzer code may as well not be there. Fuzzers will > soon find the hole. > > What do you all think? I agree, fwiw. (I don't like such arbitrary limits anyway.) Jan
This is what I'm about to commit.
int aaaa..a; where 'a' is repeated a million times, produces a
-g -gsplit-dwarf -gz .dwo file of only 2200 bytes. This might be a
silly testcase, but it demonstrates the ten times file size limit when
decompressing .debug_str.dwo is easily exceeded.
PR 26946
PR 28834
PR 34481
bfd/
* section.c (bfd_section_size_insane): Do not attempt to sanity
check compressed sections.
binutils/
* readelf.c (uncompress_section_contents): Do not limit uncompressed
section size. Remove now unused file_size param. Adjust callers.
diff --git a/bfd/section.c b/bfd/section.c
index 457486b0f89..fb2cc830dbd 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -1765,23 +1765,7 @@ bfd_section_size_insane (bfd *abfd, asection *sec)
if (sec->compress_status == DECOMPRESS_SECTION_ZSTD
|| sec->compress_status == DECOMPRESS_SECTION_ZLIB)
- {
- /* PR26946, PR28834: Sanity check compress header uncompressed
- size against the original file size, and check that the
- compressed section can be read from file. We choose an
- arbitrary uncompressed size of 10x the file size, rather than
- a compress ratio. The reason being that compiling
- "int aaa..a;" with "a" repeated enough times can result in
- compression ratios without limit for .debug_str, whereas such
- a file will usually also have the enormous symbol
- uncompressed in .symtab. */
- if (size / 10 > filesize)
- {
- bfd_set_error (bfd_error_bad_value);
- return true;
- }
- size = sec->compressed_size;
- }
+ size = sec->compressed_size;
if ((ufile_ptr) sec->filepos > filesize || size > filesize - sec->filepos)
{
diff --git a/binutils/readelf.c b/binutils/readelf.c
index b5ccc675af6..aa472947cde 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -16597,8 +16597,7 @@ static bool
uncompress_section_contents (bool is_zstd,
unsigned char ** buffer,
uint64_t uncompressed_size,
- uint64_t * size,
- uint64_t file_size)
+ uint64_t * size)
{
uint64_t compressed_size = *size;
unsigned char *compressed_buffer = *buffer;
@@ -16606,16 +16605,6 @@ uncompress_section_contents (bool is_zstd,
z_stream strm;
int rc;
- /* Similar to bfd_section_size_insane() in the BFD library we expect an
- upper limit of ~10x compression. Any compression larger than that is
- thought to be due to fuzzing of the compression header. */
- if (uncompressed_size > file_size * 10)
- {
- error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64 "\n"),
- uncompressed_size);
- goto fail;
- }
-
uncompressed_buffer = xmalloc (uncompressed_size);
if (is_zstd)
@@ -16732,7 +16721,7 @@ maybe_expand_or_relocate_section (Elf_Internal_Shdr * section,
if (uncompressed_size)
{
if (uncompress_section_contents (is_zstd, &start, uncompressed_size,
- &new_size, filedata->file_size))
+ &new_size))
{
*decomp_buf = start;
section_size = new_size;
@@ -17315,7 +17304,7 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
if (uncompressed_size)
{
if (uncompress_section_contents (is_zstd, &start, uncompressed_size,
- &size, filedata->file_size))
+ &size))
{
/* Free the compressed buffer, update the section buffer
and the section size if uncompress is successful. */
diff --git a/bfd/section.c b/bfd/section.c index 457486b0f89..13cb2fdeb2d 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -1774,11 +1774,17 @@ bfd_section_size_insane (bfd *abfd, asection *sec) "int aaa..a;" with "a" repeated enough times can result in compression ratios without limit for .debug_str, whereas such a file will usually also have the enormous symbol - uncompressed in .symtab. */ + uncompressed in .symtab. PR34481: For separare dwarf info + files we won't have a .symtab section so can't make any + assumptions about decompressed section sizes. */ if (size / 10 > filesize) { - bfd_set_error (bfd_error_bad_value); - return true; + size_t len = strlen (sec->name); + if (len < 4 || memcmp (sec->name + len - 4, ".dwo", 4) != 0) + { + bfd_set_error (bfd_error_bad_value); + return true; + } } size = sec->compressed_size; }