From patchwork Mon Jul 27 06:23:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 139973 Return-Path: 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 224FD4BA2E18 for ; Mon, 27 Jul 2026 06:24:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 224FD4BA2E18 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=b7BKhJIk X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 5C1EB4BA5435 for ; Mon, 27 Jul 2026 06:24:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C1EB4BA5435 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 5C1EB4BA5435 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::536 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785133442; cv=none; b=BUNUnReyuO6UUlW1q8hErlsnUlP8Cz6shuYh5kWPxYdKTVCdBD9IPV4mDinpPQ29iumba9VWbhY4nZHCqucR3GRxOLQbZcHhqcunNGRSpQYGdYCungSmj2CHC4kz4QoC3RHEI4RincqStkRbZdVJag0qd/aM0gmGPOONVmwOGfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785133442; c=relaxed/simple; bh=9GL9FStMi7h6QH9wAe32IfEBg6N8/GtuWA5Nkj4802k=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=H2oquyqp7ROQt8NlNZvHNGVtpCaAqTAu1ujLfqwN9t9axhI2J8qEga5JBVRKjlw86LOxjf7xfCmVNhEP/XoGIJc9LouvN6gy8eK+UaEIKWs5pMYRULKenTb8cSPwOUUrTsoNFHVaGjrTD6wJNqKZZCE9/5aD9bqolZeAWksiVJg= 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=b7BKhJIk DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C1EB4BA5435 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-cbb8b54fcf8so2272028a12.0 for ; Sun, 26 Jul 2026 23:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785133440; x=1785738240; 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=KW3x8HYLy1gFoq9kBbFOqVfYnWZ7pDVA0zE0JGOQ1Cc=; b=b7BKhJIkChIluC4rw1rSnjBJUFde5H4zkOzdZpm+VkRut5EL1c13sLxz5yHFvipe4o +abjQKxVXpnCgQf/NT00KbesmK38/W9oTAW2xFZA+olZq2qEWZAumcYgBdoW6rBn9GjX tFV/VQ1NJ7c35CiZB6D70d0zXF76LcCyK7omBxT46hc0zHOsdrWFT0YW1ElggTJwdNOi F1WmI40oBdnV4XfzuisPlIbQnE1zBKXzvwA+badsTNSv5ReJNMQtMEgJRSCvbefOqPNK LiGZ1w7Y7A84ggTuHIn0fvbD4iLxqAKxNt9lLpQNg4JAr/YSHXo7vYB3MI3HLcrdWWEA 8Bdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785133440; x=1785738240; 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=KW3x8HYLy1gFoq9kBbFOqVfYnWZ7pDVA0zE0JGOQ1Cc=; b=eOBoXfurV3RibgFeZzC1Q800vKYRgeR+od6QQvL7i7Uw89l9TpFyQ/ozVRPCIf379M AyY+2b3TVaLCnt8PlPhMjqzSvOPyOrbvzFL4CF3NQLWGros6kyTkZMBX+63xmf195+UJ hXyILWhl7aidDwUK7xLUEf+zy2J8fvI8CgA2oMTzOqm799jihwz+T6+aq11xWoC2+ZON PEgYBeiE28Zp/8tjCOnLI8RSqaTnebXQ05P2YScrrBdvjw+AsYISK06IP91U3HNpwxw+ WJ5B6AFKrhNosw8t2UnEQ1ljXbiP1Up2ZiKj2W8oR5UbWrD7a+lWEzmdGzq6itgj1un4 CgeA== X-Gm-Message-State: AOJu0YxfMdbjFXvgjQQVNkBXlHoJFiS1tsZAbgEgNaAbMfPBbB9NHCFa CBSNyAv6hIDAnIz7hBSFgZTNhR1KYkcwB3o3vupcfHz1h9pdhEg9D2Lkq9MTTg== X-Gm-Gg: AR+sD13aT1mvs48L2Nyiuvd2+BgIMmjONW0MtwNB3Y3StH0qf+wouSn4EVvZhz+vfcg GmfF6hmuoKDW6LfGCkBd1oBJb5UmGzS/B3nHaCqLFRchIeEJhp//znCT0DyEEIlMhVVcSe3a824 6aME55dHcgeK8e842EerwQPGcOTfT0WDKdp/4fMUdwllEkMsNOuFanjnxKM1DyST+E9XZKPL4RS ECdfK6e3yIlkM9XSj0JJi3vu2Ca2qMIMYZQ+aSPJf3zHpZvhSd7luJVay27NsoWAvzjUtTS1F17 trAFBHvtW4dtAUjoKPQjr8L13AJUo22ZTvrvDK1GC/A7x9tctVXb9+6H2fk/tQo+YyfzL61CMCx 16jIkhH8Pb13NymKK2nk649sR63eSgr1tfl5ylvryHkVICNzimUJwM723a3dDw28hYnvPoAC+I6 nBI68TyvEVKwPy280= X-Received: by 2002:a05:6a20:430d:b0:3c3:89cf:f55 with SMTP id adf61e73a8af0-3c67e11ab3dmr7069354637.61.1785133440237; Sun, 26 Jul 2026 23:24:00 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:6194:5a73:7e2b:1a17]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13d13015052sm47547216c88.5.2026.07.26.23.23.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2026 23:23:59 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 1A0EE1140B5D; Mon, 27 Jul 2026 15:53:57 +0930 (ACST) Date: Mon, 27 Jul 2026 15:53:57 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Use ufile_ptr for file position Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3029.5 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org This is in response to a fuzzed objcopy test that overflows file_ptr addition. It makes sense to use an unsigned value for current file offset, and allows a couple of casts to be removed. * elf.c (assign_file_positions_for_load_sections): Make off unsigned. (assign_file_positions_except_relocs): Likewise. (_bfd_elf_assign_file_positions_for_non_load): Likewise. diff --git a/bfd/elf.c b/bfd/elf.c index 6c31dabae63..ea127919b9f 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5885,7 +5885,7 @@ assign_file_positions_for_load_sections (bfd *abfd, struct elf_segment_map *phdr_load_seg; Elf_Internal_Phdr *phdrs; Elf_Internal_Phdr *p; - file_ptr off; /* Octets. */ + ufile_ptr off; /* Octets. */ bfd_size_type maxpagesize; unsigned int alloc, actual; unsigned int i, j; @@ -6175,9 +6175,9 @@ assign_file_positions_for_load_sections (bfd *abfd, { if (m->count > 0) { - if (p->p_vaddr < (bfd_vma) off + if (p->p_vaddr < off || (!m->p_paddr_valid - && p->p_paddr < (bfd_vma) off)) + && p->p_paddr < off)) { _bfd_error_handler (_("%pB: not enough room for program headers," @@ -6595,7 +6595,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd, Elf_Internal_Phdr *phdrs; Elf_Internal_Phdr *p; struct elf_segment_map *m; - file_ptr off; + ufile_ptr off; unsigned int opb = bfd_octets_per_byte (abfd, NULL); bfd_vma maxpagesize; @@ -6864,7 +6864,7 @@ assign_file_positions_except_relocs (bfd *abfd, unsigned int num_sec = elf_numsections (abfd); Elf_Internal_Shdr **hdrpp; unsigned int i; - file_ptr off; + ufile_ptr off; /* Start after the ELF header. */ off = i_ehdrp->e_ehsize; @@ -7110,7 +7110,7 @@ _bfd_elf_modify_headers (bfd *obfd, struct bfd_link_info *link_info) static bool _bfd_elf_assign_file_positions_for_non_load (bfd *abfd) { - file_ptr off; + ufile_ptr off; Elf_Internal_Shdr **shdrpp, **end_shdrpp; Elf_Internal_Shdr *shdrp; Elf_Internal_Ehdr *i_ehdrp;