diff --git a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp index 3b03f4b12b81..2d02549ce4ea 100644 --- a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp @@ -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/llvm/test/Bitcode/Inputs/invalid-abbrev-no-operands.bc b/llvm/test/Bitcode/Inputs/invalid-abbrev-no-operands.bc new file mode 100644 index 000000000000..29af122e94e2 Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-abbrev-no-operands.bc differ diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index bd6e265cbb37..9c9d54fad6c3 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -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