[BitcodeReader] Make sure abbrev records have at least one operand (record code)
authorFilipe Cabecinhas <me@filcab.net>
Tue, 26 May 2015 23:52:21 +0000 (23:52 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Tue, 26 May 2015 23:52:21 +0000 (23:52 +0000)
Bug found with AFL fuzz.

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

lib/Bitcode/Reader/BitstreamReader.cpp
test/Bitcode/Inputs/invalid-abbrev-no-operands.bc [new file with mode: 0644]
test/Bitcode/invalid.test

index 3b03f4b12b814e73f47867c627e5ec0c5d6a2f9c..2d02549ce4ea293609aa225379e19e2b5fd41e03 100644 (file)
@@ -282,6 +282,9 @@ void BitstreamCursor::ReadAbbrevRecord() {
     } else
       Abbv->Add(BitCodeAbbrevOp(E));
   }
+
+  if (Abbv->getNumOperandInfos() == 0)
+    report_fatal_error("Abbrev record with no operands");
   CurAbbrevs.push_back(Abbv);
 }
 
diff --git a/test/Bitcode/Inputs/invalid-abbrev-no-operands.bc b/test/Bitcode/Inputs/invalid-abbrev-no-operands.bc
new file mode 100644 (file)
index 0000000..29af122
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-abbrev-no-operands.bc differ
index bd6e265cbb37378f57160324b8b6451961ce2291..9c9d54fad6c373ac6f5fd4bca4de38a91059926c 100644 (file)
@@ -172,3 +172,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-global-var-comdat-id.bc 2>&1
 RUN:   FileCheck --check-prefix=INVALID-GVCOMDAT-ID %s
 
 INVALID-GVCOMDAT-ID: Invalid global variable comdat ID
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-abbrev-no-operands.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=ABBREV-NO-OPS %s
+
+ABBREV-NO-OPS: Abbrev record with no operands