Blob Blame History Raw
diff -rupN --no-dereference binutils-2.38/bfd/coffcode.h binutils-2.38-new/bfd/coffcode.h
--- binutils-2.38/bfd/coffcode.h	2022-01-22 13:14:07.000000000 +0100
+++ binutils-2.38-new/bfd/coffcode.h	2023-03-07 07:56:11.638484146 +0100
@@ -4283,10 +4283,13 @@ coff_set_section_contents (bfd * abfd,
 
 	rec = (bfd_byte *) location;
 	recend = rec + count;
-	while (rec < recend)
+	while (recend - rec >= 4)
 	  {
+	    size_t len = bfd_get_32 (abfd, rec);
+	    if (len == 0 || len > (size_t) (recend - rec) / 4)
+	      break;
+	    rec += len * 4;
 	    ++section->lma;
-	    rec += bfd_get_32 (abfd, rec) * 4;
 	  }
 
 	BFD_ASSERT (rec == recend);