summaryrefslogtreecommitdiff
path: root/lib/Bitcode/Reader
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-04-02 00:03:51 +0000
committerDan Gohman <gohman@apple.com>2010-04-02 00:03:51 +0000
commita4ae3a100d83a716dff81be7af7db5eb354517dc (patch)
tree260bb0c2ecd723b30ff2080f6c82b28a999dcbc8 /lib/Bitcode/Reader
parent7272b9200989be868f784210fb27f1935cc38036 (diff)
downloadllvm-a4ae3a100d83a716dff81be7af7db5eb354517dc.tar.gz
llvm-a4ae3a100d83a716dff81be7af7db5eb354517dc.tar.bz2
llvm-a4ae3a100d83a716dff81be7af7db5eb354517dc.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100156 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index b9453c90b5..76d112e045 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/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))