Skip to content

Commit

Permalink
[BitcodeReader] It's a malformed block if CodeLenWidth is too big
Browse files Browse the repository at this point in the history
Bug found with AFL fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237646 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
filcab committed May 19, 2015
1 parent 09f87b4 commit c3ccd67
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Bitcode/Reader/BitstreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file added test/Bitcode/Inputs/invalid-code-len-width.bc
Binary file not shown.
5 changes: 5 additions & 0 deletions test/Bitcode/invalid.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c3ccd67

Please sign in to comment.