[llvm] [NativePDB] Fix crash in llvm-pdbutil (PR #164871)

Vladimir Gorsunov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 27 14:02:38 PDT 2025


https://github.com/gv updated https://github.com/llvm/llvm-project/pull/164871

>From 8e63ca2cbde76fdbe8f1e53f6e3063a1924dde12 Mon Sep 17 00:00:00 2001
From: Vladimir Gorsunov <gorsunov at gmail.com>
Date: Thu, 23 Oct 2025 21:35:51 +0300
Subject: [PATCH] [NativePDB] Fix crash in llvm-pdbutil

Fix out of buffer read when value of --type-index was too big
---
 .../DebugInfo/CodeView/LazyRandomTypeCollection.cpp |  3 ++-
 .../PDB/Native/pdb-native-index-overflow.test       | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100755 llvm/test/DebugInfo/PDB/Native/pdb-native-index-overflow.test

diff --git a/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp b/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp
index 6c23ba8f3c466..23ab5344df1ed 100644
--- a/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp
+++ b/llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp
@@ -102,7 +102,8 @@ std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) {
     return std::nullopt;
   }
 
-  assert(contains(Index));
+  if (!contains(Index))
+    return std::nullopt;
   return Records[Index.toArrayIndex()].Type;
 }
 
diff --git a/llvm/test/DebugInfo/PDB/Native/pdb-native-index-overflow.test b/llvm/test/DebugInfo/PDB/Native/pdb-native-index-overflow.test
new file mode 100755
index 0000000000000..aa3f6dcb9632a
--- /dev/null
+++ b/llvm/test/DebugInfo/PDB/Native/pdb-native-index-overflow.test
@@ -0,0 +1,13 @@
+; Test that the native PDB reader isn't crashed by index value bigger than
+; number of types in TPI or IPI stream
+; RUN: llvm-pdbutil dump %p/../Inputs/empty.pdb --type-index=20000000\
+; RUN:   | FileCheck -check-prefixes=TYPES,NOT_FOUND %s
+; RUN: llvm-pdbutil dump %p/../Inputs/empty.pdb --id-index=20000000\
+; RUN:   | FileCheck -check-prefixes=IDS,NOT_FOUND %s
+
+TYPES:                     Types (TPI Stream)
+IDS:                       Types (IPI Stream)
+NOT_FOUND:============================================================
+NOT_FOUND:  Showing 1 records.
+NOT_FOUND:  Type 0x1312D00 doesn't exist in TPI stream
+



More information about the llvm-commits mailing list