Skip to content

Commit 6f170eb

Browse files
gvaganea
authored andcommitted
[NativePDB] Fix crash in llvm-pdbutil (llvm#164871)
Fix out of buffer read when value of --type-index was too big Co-authored-by: Alexandre Ganea <[email protected]>
1 parent 61fbf32 commit 6f170eb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) {
102102
return std::nullopt;
103103
}
104104

105-
assert(contains(Index));
105+
if (!contains(Index))
106+
return std::nullopt;
106107
return Records[Index.toArrayIndex()].Type;
107108
}
108109

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; Test that the native PDB reader isn't crashed by index value bigger than
2+
; number of types in TPI or IPI stream
3+
; RUN: llvm-pdbutil dump %p/../Inputs/empty.pdb --type-index=20000000\
4+
; RUN: | FileCheck -check-prefixes=TYPES,NOT_FOUND %s
5+
; RUN: llvm-pdbutil dump %p/../Inputs/empty.pdb --id-index=20000000\
6+
; RUN: | FileCheck -check-prefixes=IDS,NOT_FOUND %s
7+
8+
TYPES: Types (TPI Stream)
9+
IDS: Types (IPI Stream)
10+
NOT_FOUND:============================================================
11+
NOT_FOUND: Showing 1 records.
12+
NOT_FOUND: Type 0x1312D00 doesn't exist in TPI stream
13+

0 commit comments

Comments
 (0)