From b0ed17be63fa9f1af6b5367b65b398d3331845da Mon Sep 17 00:00:00 2001 From: Filipe Cabecinhas Date: Thu, 29 Oct 2015 23:37:28 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251667 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 4 +++- test/Bitcode/Inputs/invalid-no-function-block.bc | Bin 0 -> 548 bytes test/Bitcode/invalid.test | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/Bitcode/Inputs/invalid-no-function-block.bc diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index e23f8176330..d2cbe9e85a4 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3054,7 +3054,9 @@ std::error_code BitcodeReader::rememberAndSkipFunctionBodies() { 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); diff --git a/test/Bitcode/Inputs/invalid-no-function-block.bc b/test/Bitcode/Inputs/invalid-no-function-block.bc new file mode 100644 index 0000000000000000000000000000000000000000..52b65588e4a72ef92a824a67dc8d4d5c1f07e1ec GIT binary patch literal 548 zcmZ>AK5)-egn@yTfq@~3$3Vp=a^JJJpY3uLE(G=2 zaJQuR2#6>%6tg4*u(X&60F^R0%Q1o|2>4{c5C&u!b2P{tc_@=6!f4y!Y|(PK$Ekt6 zvVy&MMj_8L2L87Kd|w*)jCq{o4jq&|w@@a{fEBE)S^5mK?Fnbw9%kD!6+I;d?A09X zl^*Q{1?*J?%w-kr1q$twX9W4)OyGNHz@KNp|M&ynhX6iffg`f_6lHEG${tFTOEc)S z-qUP-!P#;Pv(27nn-*s4Gap3C64r~m)} literal 0 HcmV?d00001 diff --git a/test/Bitcode/invalid.test b/test/Bitcode/invalid.test index 69104046df2..24ccd8bccd5 100644 --- a/test/Bitcode/invalid.test +++ b/test/Bitcode/invalid.test @@ -207,3 +207,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-alias-type-mismatch.bc 2>&1 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 -- 2.34.1