summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/ValueList.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-07-14 12:35:50 +0000
committerFlorian Hahn <flo@fhahn.com>2019-07-14 12:35:50 +0000
commit864474c9c72a647e1d9bc7546df86103ce043f4f (patch)
treec585ae7e2f6d2500f9728a1e99058e4d01c1a8e6 /llvm/lib/Bitcode/Reader/ValueList.cpp
parentf66f5ff38ab25043aed6e379b27a298196e764b9 (diff)
downloadbcm5719-llvm-864474c9c72a647e1d9bc7546df86103ce043f4f.tar.gz
bcm5719-llvm-864474c9c72a647e1d9bc7546df86103ce043f4f.zip
[BitcodeReader] Use tighter upper bound to validate forward references.
At the moment, bitcode files with invalid forward reference can easily cause the bitcode reader to run out of memory, by creating a forward reference with a very high index. We can use the size of the bitcode file as an upper bound, because a valid bitcode file can never contain more records. This should be sufficient to fail early in most cases. The only exception is large files with invalid forward references close to the file size. There are a couple of clusterfuzz runs that fail with out-of-memory because of very high forward references and they should be fixed by this patch. A concrete example for this is D64507, which causes out-of-memory on systems with low memory, like the hexagon upstream bots. Reviewers: t.p.northover, thegameg, jfb, efriedma, hfinkel Reviewed By: jfb Differential Revision: https://reviews.llvm.org/D64577 llvm-svn: 366017
Diffstat (limited to 'llvm/lib/Bitcode/Reader/ValueList.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/ValueList.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/ValueList.cpp b/llvm/lib/Bitcode/Reader/ValueList.cpp
index da2d24d103b..431995fd40a 100644
--- a/llvm/lib/Bitcode/Reader/ValueList.cpp
+++ b/llvm/lib/Bitcode/Reader/ValueList.cpp
@@ -97,6 +97,10 @@ void BitcodeReaderValueList::assignValue(Value *V, unsigned Idx, Type *FullTy) {
}
Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx, Type *Ty) {
+ // Bail out for a clearly invalid value.
+ if (Idx >= RefsUpperBound)
+ return nullptr;
+
if (Idx >= size())
resize(Idx + 1);
@@ -114,8 +118,8 @@ Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx, Type *Ty) {
Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty,
Type **FullTy) {
- // Bail out for a clearly invalid value. This would make us call resize(0)
- if (Idx == std::numeric_limits<unsigned>::max())
+ // Bail out for a clearly invalid value.
+ if (Idx >= RefsUpperBound)
return nullptr;
if (Idx >= size())
OpenPOWER on IntegriCloud