diff options
author | Nikita Popov <npopov@redhat.com> | 2022-02-07 11:43:29 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-02-07 12:16:13 +0100 |
commit | ec18030f5fc1f4a08326e65fe06c6f265a829f4c (patch) | |
tree | 31fa1514db2008f643374fac1c83fffacf833622 /llvm/lib/Bitstream/Reader/BitstreamReader.cpp | |
parent | 89017772d9a7dc66398227fe23a9f8a1f5fabda3 (diff) | |
download | llvm-ec18030f5fc1f4a08326e65fe06c6f265a829f4c.zip llvm-ec18030f5fc1f4a08326e65fe06c6f265a829f4c.tar.gz llvm-ec18030f5fc1f4a08326e65fe06c6f265a829f4c.tar.bz2 |
[Bitstream] Check that there is enough space for blob
Instead of simply assuming that it will be zero. I double checked
that the bitstream reader doesn't have any special handling for
all-zero blobs, it will always write out the full contents.
Diffstat (limited to 'llvm/lib/Bitstream/Reader/BitstreamReader.cpp')
-rw-r--r-- | llvm/lib/Bitstream/Reader/BitstreamReader.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp index f924790..b2da7e7 100644 --- a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp +++ b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp @@ -331,13 +331,9 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID, size_t CurBitPos = GetCurrentBitNo(); const size_t NewEnd = CurBitPos + alignTo(NumElts, 4) * 8; - // If this would read off the end of the bitcode file, just set the - // record to empty and return. - if (!canSkipToPos(NewEnd/8)) { - Vals.append(NumElts, 0); - skipToEnd(); - break; - } + // Make sure the bitstream is large enough to contain the blob. + if (!canSkipToPos(NewEnd/8)) + return error("Blob ends too soon"); // Otherwise, inform the streamer that we need these bytes in memory. Skip // over tail padding first, in case jumping to NewEnd invalidates the Blob |