From: Filipe Cabecinhas Date: Tue, 19 May 2015 00:34:17 +0000 (+0000) Subject: [BitcodeReader] It's a malformed block if CodeLenWidth is too big X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c3ccd67d726a284addde38c9d96dda666143274a;p=oota-llvm.git [BitcodeReader] It's a malformed block if CodeLenWidth is too big Bug found with AFL fuzz. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237646 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Bitcode/Reader/BitstreamReader.cpp b/lib/Bitcode/Reader/BitstreamReader.cpp index dff6d181486..450bbbc4558 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 00000000000..c8e8c4f6653 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 921d4e62c04..c4c635e08d3 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