diff options
author | Derek Schuff <dschuff@google.com> | 2015-05-21 19:40:19 +0000 |
---|---|---|
committer | Derek Schuff <dschuff@google.com> | 2015-05-21 19:40:19 +0000 |
commit | fcfd5ae82c93f9ff350fac4e7fb07d774139e1a5 (patch) | |
tree | f1b93053fc5cc40ead2dc95c2a81057f24ec968e /llvm/lib/Support/StreamingMemoryObject.cpp | |
parent | 286875874af11c4c5a1acd950b4dd82c556ce344 (diff) | |
download | bcm5719-llvm-fcfd5ae82c93f9ff350fac4e7fb07d774139e1a5.tar.gz bcm5719-llvm-fcfd5ae82c93f9ff350fac4e7fb07d774139e1a5.zip |
Fix StreamingMemoryObject to respect known object size.
The existing code for method StreamingMemoryObject.fetchToPos does not respect
the corresonding call to setKnownObjectSize(). As a result, it allows the
StreamingMemoryObject to read bytes past the object size.
This patch provides a test case, and code to fix the problem.
Patch by Karl Schimpf
Differential Revision: http://reviews.llvm.org/D8931
llvm-svn: 237939
Diffstat (limited to 'llvm/lib/Support/StreamingMemoryObject.cpp')
-rw-r--r-- | llvm/lib/Support/StreamingMemoryObject.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/llvm/lib/Support/StreamingMemoryObject.cpp b/llvm/lib/Support/StreamingMemoryObject.cpp index 90f3ed80d12..6c5652af04c 100644 --- a/llvm/lib/Support/StreamingMemoryObject.cpp +++ b/llvm/lib/Support/StreamingMemoryObject.cpp @@ -73,7 +73,7 @@ namespace llvm { // block until we actually want to read it. bool StreamingMemoryObject::isValidAddress(uint64_t address) const { if (ObjectSize && address < ObjectSize) return true; - return fetchToPos(address); + return fetchToPos(address); } uint64_t StreamingMemoryObject::getExtent() const { @@ -87,13 +87,18 @@ uint64_t StreamingMemoryObject::getExtent() const { uint64_t StreamingMemoryObject::readBytes(uint8_t *Buf, uint64_t Size, uint64_t Address) const { fetchToPos(Address + Size - 1); - if (Address >= BytesRead) + // Note: For wrapped bitcode files will set ObjectSize after the + // first call to fetchToPos. In such cases, ObjectSize can be + // smaller than BytesRead. + size_t MaxAddress = + (ObjectSize && ObjectSize < BytesRead) ? ObjectSize : BytesRead; + if (Address >= MaxAddress) return 0; uint64_t End = Address + Size; - if (End > BytesRead) - End = BytesRead; - assert(static_cast<int64_t>(End - Address) >= 0); + if (End > MaxAddress) + End = MaxAddress; + assert(End >= Address); Size = End - Address; memcpy(Buf, &Bytes[Address + BytesSkipped], Size); return Size; @@ -109,6 +114,8 @@ bool StreamingMemoryObject::dropLeadingBytes(size_t s) { void StreamingMemoryObject::setKnownObjectSize(size_t size) { ObjectSize = size; Bytes.reserve(size); + if (ObjectSize <= BytesRead) + EOFReached = true; } MemoryObject *getNonStreamedMemoryObject(const unsigned char *Start, |