diff options
author | Dan Gohman <gohman@apple.com> | 2010-04-02 00:03:51 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-04-02 00:03:51 +0000 |
commit | e447aeb9fe7ca0d5597056d53cf82b588d274048 (patch) | |
tree | e35ef37d26aa4491bd7b9035411a36470ed96960 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | d79b4d81736d8c3dcd017dc7b13a87898d955182 (diff) | |
download | bcm5719-llvm-e447aeb9fe7ca0d5597056d53cf82b588d274048.tar.gz bcm5719-llvm-e447aeb9fe7ca0d5597056d53cf82b588d274048.zip |
If the bitcode reader input stream isn't a multiple of 4 bytes, it's more
likely not a bitcode file at all, rather than being a bitcode file which
is truncated. Check for this case and issue a more relevant error message.
llvm-svn: 100156
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index b9453c90b58..76d112e045a 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1527,12 +1527,16 @@ bool BitcodeReader::ParseModule() { bool BitcodeReader::ParseBitcodeInto(Module *M) { TheModule = 0; - if (Buffer->getBufferSize() & 3) - return Error("Bitcode stream should be a multiple of 4 bytes in length"); - unsigned char *BufPtr = (unsigned char *)Buffer->getBufferStart(); unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); + if (Buffer->getBufferSize() & 3) { + if (!isRawBitcode(BufPtr, BufEnd) && !isBitcodeWrapper(BufPtr, BufEnd)) + return Error("Invalid bitcode signature"); + else + return Error("Bitcode stream should be a multiple of 4 bytes in length"); + } + // If we have a wrapper header, parse it and ignore the non-bc file contents. // The magic number is 0x0B17C0DE stored in little endian. if (isBitcodeWrapper(BufPtr, BufEnd)) |