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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285777 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Peter Collingbourne
2016-11-02 00:39:11 +00:00
parent 4ac35e8272
commit 772d912885
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 ||