diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3407,9 +3407,12 @@ // Record[16] is the address space number. - // Check whether we have enough values to read a partition name. - if (Record.size() > 18) + // Check whether we have enough values to read a partition name. Also make + // sure Strtab has enough values. + if (Record.size() > 18 && Strtab.data() && + Record[17] + Record[18] <= Strtab.size()) { Func->setPartition(StringRef(Strtab.data() + Record[17], Record[18])); + } ValueList.push_back(Func); diff --git a/llvm/test/Bitcode/invalid-record-strtab.ll b/llvm/test/Bitcode/invalid-record-strtab.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Bitcode/invalid-record-strtab.ll @@ -0,0 +1,5 @@ +; Bitcode with an invalid record that indexes a name outside of strtab. + +; RUN: not llvm-dis %s.bc -o - 2>&1 | FileCheck %s + +; CHECK: error: Invalid record diff --git a/llvm/test/Bitcode/invalid-record-strtab.ll.bc b/llvm/test/Bitcode/invalid-record-strtab.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@