[PATCH] Error out of ParseBitcodeInto(Module*) if we haven't read a Module
Duncan Exon Smith
dexonsmith at apple.com
Tue Apr 14 06:55:44 PDT 2015
> On Apr 14, 2015, at 6:00 AM, Filipe Cabecinhas <filcab+llvm.phabricator at gmail.com> wrote:
>
> Hi dexonsmith, rafael,
>
> 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.
>
> http://reviews.llvm.org/D9014
LGTM with one whitespace nit.
>
> Files:
> lib/Bitcode/Reader/BitcodeReader.cpp
> test/Bitcode/Inputs/invalid-no-proper-module.bc
> test/Bitcode/invalid.test
>
> Index: lib/Bitcode/Reader/BitcodeReader.cpp
> ===================================================================
> --- lib/Bitcode/Reader/BitcodeReader.cpp
> +++ lib/Bitcode/Reader/BitcodeReader.cpp
> @@ -3063,8 +3063,12 @@
> // 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
Period (".") at the end of the sentence.
> + return Error("Malformed IR file");
> + }
>
> BitstreamEntry Entry =
> Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);
> Index: test/Bitcode/invalid.test
> ===================================================================
> --- test/Bitcode/invalid.test
> +++ test/Bitcode/invalid.test
> @@ -50,3 +50,8 @@
> 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
>
> EMAIL PREFERENCES
> http://reviews.llvm.org/settings/panel/emailpreferences/
> <D9014.23729.patch>
More information about the llvm-commits
mailing list