[BitcodeReader] It's a malformed block if CodeLenWidth is too big
authorFilipe Cabecinhas <me@filcab.net>
Tue, 19 May 2015 00:34:17 +0000 (00:34 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Tue, 19 May 2015 00:34:17 +0000 (00:34 +0000)
Bug found with AFL fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237646 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitstreamReader.cpp
test/Bitcode/Inputs/invalid-code-len-width.bc [new file with mode: 0644]
test/Bitcode/invalid.test

index dff6d181486a5320fa1f34a8fea063ed73036b24..450bbbc4558772051f9ab01cad436f3fd9ee0211 100644 (file)
@@ -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 (file)
index 0000000..c8e8c4f
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-code-len-width.bc differ
index 921d4e62c04918933098047b3eece52a4e82c539..c4c635e08d395753447406804d97155566cc5b1e 100644 (file)
@@ -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