[bitcode reader] Fix an assert on invalid type tables
authorFilipe Cabecinhas <me@filcab.net>
Fri, 30 Jan 2015 10:57:58 +0000 (10:57 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Fri, 30 Jan 2015 10:57:58 +0000 (10:57 +0000)
Bug found with afl-fuzz

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

lib/Bitcode/Reader/BitcodeReader.cpp
test/Bitcode/Inputs/invalid-type-table-forward-ref.bc [new file with mode: 0644]

index 9e27225df7996790e33a702118efa655879fbc93..c3589bce3980c0a7507cf00811806ee454bd7627 100644 (file)
@@ -1095,8 +1095,10 @@ std::error_code BitcodeReader::ParseTypeTableBody() {
 
     if (NumRecords >= TypeList.size())
       return Error("Invalid TYPE table");
+    if (TypeList[NumRecords])
+      return Error(
+          "Invalid TYPE table: Only named structs can be forward referenced");
     assert(ResultTy && "Didn't read a type?");
-    assert(!TypeList[NumRecords] && "Already read type?");
     TypeList[NumRecords++] = ResultTy;
   }
 }
diff --git a/test/Bitcode/Inputs/invalid-type-table-forward-ref.bc b/test/Bitcode/Inputs/invalid-type-table-forward-ref.bc
new file mode 100644 (file)
index 0000000..4594efe
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-type-table-forward-ref.bc differ