Skip to content

Commit 7224871

Browse files
committed
[Bitcode] Check minimum size of constant GEP record
Checking this early, because we may end up reading up to two records before the operands.
1 parent 73a961b commit 7224871

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,8 @@ Error BitcodeReader::parseConstants() {
26762676
case bitc::CST_CODE_CE_GEP: // [ty, n x operands]
26772677
case bitc::CST_CODE_CE_GEP_WITH_INRANGE_INDEX: { // [ty, flags, n x
26782678
// operands]
2679+
if (Record.size() < 2)
2680+
return error("Constant GEP record must have at least two elements");
26792681
unsigned OpNum = 0;
26802682
Type *PointeeType = nullptr;
26812683
if (BitCode == bitc::CST_CODE_CE_GEP_WITH_INRANGE_INDEX ||
28 Bytes
Binary file not shown.

llvm/test/Bitcode/invalid.test

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ VOID-CONSTANT-TYPE: Invalid constant type
219219
RUN: not llvm-dis -disable-output %p/Inputs/invalid-gep-no-operands.bc 2>&1 | \
220220
RUN: FileCheck --check-prefix=GEP-NO-OPERANDS %s
221221

222-
GEP-NO-OPERANDS: Invalid gep with no operands
222+
GEP-NO-OPERANDS: Constant GEP record must have at least two elements
223+
224+
RUN: not llvm-dis -disable-output %p/Inputs/invalid-constant-gep.bc 2>&1 | \
225+
RUN: FileCheck --check-prefix=INVALID-CONSTANT-GEP %s
226+
227+
INVALID-CONSTANT-GEP: Constant GEP record must have at least two elements
223228

224229
RUN: not llvm-dis -disable-output %p/Inputs/invalid-nonpointer-storeatomic.bc 2>&1 | \
225230
RUN: FileCheck --check-prefix=NONPOINTER-STOREATOMIC %s

0 commit comments

Comments
 (0)