[lld] [lld][macho] Fix segfault while processing malformed object file. (PR #167025)

Prabhu Rajasekaran via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 14:12:22 PST 2025


https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/167025

None

>From e1ced6fbe18191dc2ac70ec1e9e3387a09140dac Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Fri, 7 Nov 2025 13:46:44 -0800
Subject: [PATCH] [lld][macho] Fix segfault while processing malformed object
 file.

---
 lld/MachO/InputFiles.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 20e4a1d755229..add59272d9f67 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -808,6 +808,11 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
       continue;
 
     if ((sym.n_type & N_TYPE) == N_SECT) {
+      if (sym.n_sect == 0) {
+        error("Section symbol " + StringRef(strtab + sym.n_strx) + " in " +
+              toString(this) + " has an invalid section index of 0");
+        llvm_unreachable("Section symbol without an associated section.");
+      }
       Subsections &subsections = sections[sym.n_sect - 1]->subsections;
       // parseSections() may have chosen not to parse this section.
       if (subsections.empty())



More information about the llvm-commits mailing list