[llvm] r285777 - Bitcode: Check file size before reading bitcode header.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 17:39:11 PDT 2016
Author: pcc
Date: Tue Nov 1 19:39:11 2016
New Revision: 285777
URL: http://llvm.org/viewvc/llvm-project?rev=285777&view=rev
Log:
Bitcode: Check file size before reading bitcode header.
Should unbreak ocaml binding tests.
Also added an llvm-dis test that checks for the same thing.
Added:
llvm/trunk/test/Bitcode/Inputs/invalid-empty.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=285777&r1=285776&r2=285777&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Nov 1 19:39:11 2016
@@ -4144,7 +4144,8 @@ std::error_code BitcodeReader::parseModu
/// Helper to read the header common to all bitcode files.
static bool hasValidBitcodeHeader(BitstreamCursor &Stream) {
// Sniff for the signature.
- if (Stream.Read(8) != 'B' ||
+ if (!Stream.canSkipToPos(4) ||
+ Stream.Read(8) != 'B' ||
Stream.Read(8) != 'C' ||
Stream.Read(4) != 0x0 ||
Stream.Read(4) != 0xC ||
Added: llvm/trunk/test/Bitcode/Inputs/invalid-empty.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/invalid-empty.bc?rev=285777&view=auto
==============================================================================
(empty)
Modified: llvm/trunk/test/Bitcode/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid.test?rev=285777&r1=285776&r2=285777&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/invalid.test (original)
+++ llvm/trunk/test/Bitcode/invalid.test Tue Nov 1 19:39:11 2016
@@ -1,3 +1,5 @@
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-empty.bc 2>&1 | \
+RUN: FileCheck --check-prefix=INVALID-EMPTY %s
RUN: not llvm-dis -disable-output %p/Inputs/invalid-pr20485.bc 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-ENCODING %s
RUN: not llvm-dis -disable-output %p/Inputs/invalid-abbrev.bc 2>&1 | \
@@ -27,6 +29,7 @@ RUN: FileCheck --check-prefix=MISMATCH
RUN: not llvm-dis -disable-output %p/Inputs/invalid-invoke-non-function-explicit-type.bc 2>&1 | \
RUN: FileCheck --check-prefix=NON-FUNCTION-EXPLICIT-INVOKE %s
+INVALID-EMPTY: Invalid bitcode signature
INVALID-ENCODING: Invalid encoding
BAD-ABBREV: Abbreviation starts with an Array or a Blob
UNEXPECTED-EOF: Unexpected end of file
More information about the llvm-commits
mailing list