diff --git a/lib/Bitcode/Reader/BitstreamReader.cpp b/lib/Bitcode/Reader/BitstreamReader.cpp index dff6d181486a..450bbbc45587 100644 --- a/lib/Bitcode/Reader/BitstreamReader.cpp +++ b/lib/Bitcode/Reader/BitstreamReader.cpp @@ -39,6 +39,10 @@ bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { // Get the codesize of this block. CurCodeSize = ReadVBR(bitc::CodeLenWidth); + // We can't read more than MaxChunkSize at a time + if (CurCodeSize > MaxChunkSize) + return true; + SkipToFourByteBoundary(); unsigned NumWords = Read(bitc::BlockSizeWidth); if (NumWordsP) *NumWordsP = NumWords; diff --git a/test/Bitcode/Inputs/invalid-code-len-width.bc b/test/Bitcode/Inputs/invalid-code-len-width.bc new file mode 100644 index 000000000000..c8e8c4f66538 Binary files /dev/null and b/test/Bitcode/Inputs/invalid-code-len-width.bc differ diff --git a/test/Bitcode/invalid.test b/test/Bitcode/invalid.test index 921d4e62c049..c4c635e08d39 100644 --- a/test/Bitcode/invalid.test +++ b/test/Bitcode/invalid.test @@ -147,3 +147,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-inserted-value-type-mismatch RUN: FileCheck --check-prefix=INSERT-TYPE-MISMATCH %s INSERT-TYPE-MISMATCH: Inserted value type doesn't match aggregate type + +RUN: not llvm-dis -disable-output %p/Inputs/invalid-code-len-width.bc 2>&1 | \ +RUN: FileCheck --check-prefix=INVALID-CODELENWIDTH %s + +INVALID-CODELENWIDTH: Malformed block