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.

llvm-svn: 285777
This commit is contained in:
Peter Collingbourne
2016-11-02 00:39:11 +00:00
parent 07b83767a0
commit ff2c2ec6b2
3 changed files with 5 additions and 1 deletions

View File

@@ -4144,7 +4144,8 @@ std::error_code BitcodeReader::parseModule(uint64_t ResumeBit,
/// 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 ||