Make sure we don't resize(0) when we get a fwdref with Idx == UINT_MAX
authorFilipe Cabecinhas <me@filcab.net>
Thu, 30 Apr 2015 00:52:42 +0000 (00:52 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Thu, 30 Apr 2015 00:52:42 +0000 (00:52 +0000)
Make it an error instead.

Bug found with AFL fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236190 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
test/Bitcode/Inputs/invalid-too-big-fwdref.bc [new file with mode: 0644]
test/Bitcode/invalid.test

index f49a53805c94fbd246f90942035c852faddb487a..7778125e2d482226a37034e86d63836b79bcc8b6 100644 (file)
@@ -790,6 +790,10 @@ Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx,
 }
 
 Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty) {
+  // Bail out for a clearly invalid value. This would make us call resize(0)
+  if (Idx == UINT_MAX)
+    return nullptr;
+
   if (Idx >= size())
     resize(Idx + 1);
 
diff --git a/test/Bitcode/Inputs/invalid-too-big-fwdref.bc b/test/Bitcode/Inputs/invalid-too-big-fwdref.bc
new file mode 100644 (file)
index 0000000..d1d51a6
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-too-big-fwdref.bc differ
index c18ff3d3f61e1639f396c511e9a1fcc621c9ca5c..077f35151286d026e2c1b6f904ffdb81903de9dc 100644 (file)
@@ -112,3 +112,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-op-not-2nd-to-last.bc
 RUN:   FileCheck --check-prefix=ARRAY-NOT-2LAST %s
 
 ARRAY-NOT-2LAST: Array op not second to last
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-too-big-fwdref.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=HUGE-FWDREF %s
+
+HUGE-FWDREF: Invalid record