[llvm] r234887 - Error out of ParseBitcodeInto(Module*) if we haven't read a Module

Filipe Cabecinhas me at filcab.net
Tue Apr 14 07:07:15 PDT 2015


Author: filcab
Date: Tue Apr 14 09:07:15 2015
New Revision: 234887

URL: http://llvm.org/viewvc/llvm-project?rev=234887&view=rev
Log:
Error out of ParseBitcodeInto(Module*) if we haven't read a Module

Summary:
Without this check the following case failed:

Skip a SubBlock which is not a MODULE_BLOCK_ID nor a BLOCKINFO_BLOCK_ID
Got to end of file

TheModule would still be == nullptr, and we would subsequentially fail
when materializing the Module (assert at the start of
BitcodeReader::MaterializeModule).

Bug found with AFL.

Reviewers: dexonsmith, rafael

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9014

Added:
    llvm/trunk/test/Bitcode/Inputs/invalid-no-proper-module.bc
Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/test/Bitcode/invalid.test

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=234887&r1=234886&r2=234887&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Apr 14 09:07:15 2015
@@ -3063,8 +3063,12 @@ std::error_code BitcodeReader::ParseBitc
   // We expect a number of well-defined blocks, though we don't necessarily
   // need to understand them all.
   while (1) {
-    if (Stream.AtEndOfStream())
-      return std::error_code();
+    if (Stream.AtEndOfStream()) {
+      if (TheModule)
+        return std::error_code();
+      // We didn't really read a proper Module.
+      return Error("Malformed IR file");
+    }
 
     BitstreamEntry Entry =
       Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);

Added: llvm/trunk/test/Bitcode/Inputs/invalid-no-proper-module.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/invalid-no-proper-module.bc?rev=234887&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/invalid-no-proper-module.bc (added) and llvm/trunk/test/Bitcode/Inputs/invalid-no-proper-module.bc Tue Apr 14 09:07:15 2015 differ

Modified: llvm/trunk/test/Bitcode/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid.test?rev=234887&r1=234886&r2=234887&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/invalid.test (original)
+++ llvm/trunk/test/Bitcode/invalid.test Tue Apr 14 09:07:15 2015
@@ -50,3 +50,8 @@ EXTRACT-IDXS: EXTRACTVAL: Invalid type
 INSERT-ARRAY: INSERTVAL: Invalid array index
 INSERT-STRUCT: INSERTVAL: Invalid struct index
 INSERT-IDXS: INSERTVAL: Invalid type
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-no-proper-module.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=NO-MODULE %s
+
+NO-MODULE: Malformed IR file





More information about the llvm-commits mailing list