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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-macho

Author: Prabhu Rajasekaran (Prabhuk)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/167025.diff


1 Files Affected:

- (modified) lld/MachO/InputFiles.cpp (+5) 


``````````diff
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())

``````````

</details>


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


More information about the llvm-commits mailing list