diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index d07edefcffa..6cad3b94e5e 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4171,6 +4171,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) { popValue(Record, OpNum, NextValueNo, LHS->getType(), RHS)) return error("Invalid record"); + if (OpNum >= Record.size()) + return error( + "Invalid record: operand number exceeded available operands"); + unsigned PredVal = Record[OpNum]; bool IsFP = LHS->getType()->isFPOrFPVectorTy(); FastMathFlags FMF; diff --git a/test/Bitcode/Inputs/invalid-fcmp-opnum.bc b/test/Bitcode/Inputs/invalid-fcmp-opnum.bc new file mode 100644 index 00000000000..454a14b8611 Binary files /dev/null and b/test/Bitcode/Inputs/invalid-fcmp-opnum.bc differ diff --git a/test/Bitcode/invalid.test b/test/Bitcode/invalid.test index 2a9af0626c6..d1f9d7c0874 100644 --- a/test/Bitcode/invalid.test +++ b/test/Bitcode/invalid.test @@ -235,3 +235,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-nonpointer-atomicrmw.bc 2>&1 RUN: FileCheck --check-prefix=NONPOINTER-ATOMICRMW %s NONPOINTER-ATOMICRMW: Invalid record + +RUN: not llvm-dis -disable-output %p/Inputs/invalid-fcmp-opnum.bc 2>&1 | \ +RUN: FileCheck --check-prefix=INVALID-FCMP-OPNUM %s + +INVALID-FCMP-OPNUM: Invalid record: operand number exceeded available operands