aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2021-06-22 14:48:45 +0100
committerFlorian Hahn <flo@fhahn.com>2021-06-22 14:52:16 +0100
commit34cccdaed7e7952a9191231ffa62b1b22eac35c8 (patch)
tree79ef62c684422646e1246c2f695df0bf39e787cc /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parente638a290f7d0bb85dbf81ba34eaaeef8c8d1b42d (diff)
downloadllvm-34cccdaed7e7952a9191231ffa62b1b22eac35c8.zip
llvm-34cccdaed7e7952a9191231ffa62b1b22eac35c8.tar.gz
llvm-34cccdaed7e7952a9191231ffa62b1b22eac35c8.tar.bz2
[BitcodeReader] Validate Strtab before accessing.
This fixes a crash with invalid bitcode files that have records referencing names in Strtab, but Strtab is not present or the index is out-of-bounds. This fixes the following clusterfuzz issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29895 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D95554
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index e002019..1631dc3 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3407,9 +3407,12 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) {
// 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);