UB in coff_compute_section_file_positions

Message ID arcMrGovO3mPLDoE@squeak.grove.modra.org
State New
Headers
Series UB in coff_compute_section_file_positions |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Sept. 26, 2026, 12:07 a.m. UTC
  objcopy with an input having fuzzed section alignment can result in
trying to align sections to large boundaries, ones that result in
file_ptr overflow since the type is signed.  Fix this by using
ufile_ptr.  I don't care to catch ufile_ptr overflow and report an
error as fuzzed objects are a case of garbage in garbage out.
  

Patch

diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 784ed19f494..b291ac8d052 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -2986,12 +2986,12 @@  static bool
 coff_compute_section_file_positions (bfd * abfd)
 {
   asection *current;
-  file_ptr sofar = bfd_coff_filhsz (abfd);
+  ufile_ptr sofar = bfd_coff_filhsz (abfd);
   bool align_adjust;
   unsigned int target_index;
 #ifdef ALIGN_SECTIONS_IN_FILE
   asection *previous = NULL;
-  file_ptr old_sofar;
+  ufile_ptr old_sofar;
 #endif
 
 #ifdef COFF_IMAGE_WITH_PE