[llvm] r251910 - Don't assert if materializing before seeing any function bodies

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 05:48:27 PST 2015


Author: filcab
Date: Tue Nov  3 07:48:26 2015
New Revision: 251910

URL: http://llvm.org/viewvc/llvm-project?rev=251910&view=rev
Log:
Don't assert if materializing before seeing any function bodies

This assert was reachable from user input. A minimized test case (no
FUNCTION_BLOCK_ID record) is attached.

Bug found with afl-fuzz

Added:
    llvm/trunk/test/Bitcode/Inputs/invalid-no-function-block.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=251910&r1=251909&r2=251910&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Nov  3 07:48:26 2015
@@ -3055,7 +3055,9 @@ std::error_code BitcodeReader::rememberA
   if (Stream.AtEndOfStream())
     return error("Could not find function in stream");
 
-  assert(SeenFirstFunctionBody);
+  if (!SeenFirstFunctionBody)
+    return error("Trying to materialize functions before seeing function blocks");
+
   // An old bitcode file with the symbol table at the end would have
   // finished the parse greedily.
   assert(SeenValueSymbolTable);

Added: llvm/trunk/test/Bitcode/Inputs/invalid-no-function-block.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/invalid-no-function-block.bc?rev=251910&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/invalid-no-function-block.bc (added) and llvm/trunk/test/Bitcode/Inputs/invalid-no-function-block.bc Tue Nov  3 07:48:26 2015 differ

Modified: llvm/trunk/test/Bitcode/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid.test?rev=251910&r1=251909&r2=251910&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/invalid.test (original)
+++ llvm/trunk/test/Bitcode/invalid.test Tue Nov  3 07:48:26 2015
@@ -207,3 +207,8 @@ RUN: not llvm-dis -disable-output %p/Inp
 RUN:   FileCheck --check-prefix=ALIAS-TYPE-MISMATCH %s
 
 ALIAS-TYPE-MISMATCH: Alias and aliasee types don't match
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-no-function-block.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=NO-FUNCTION-BLOCK %s
+
+NO-FUNCTION-BLOCK: Trying to materialize functions before seeing function blocks




More information about the llvm-commits mailing list