summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorcmumford <cmumford@google.com>2019-03-19 17:10:56 -0700
committerVictor Costan <pwnall@chromium.org>2019-03-20 13:56:39 -0700
commitce399ac28af7023b1aff0ede4986cb6d89b3c0b5 (patch)
tree425e9d65f86fe2fc4a4feaf26c5e366fef809f97 /helpers
parent201f77d137f30ea46e789a2ad60e9119b6f990fc (diff)
downloadleveldb-ce399ac28af7023b1aff0ede4986cb6d89b3c0b5.tar.gz
Always copy bytes to scratch buffer when reading w/MemEnv.
FileState::Read (used by InMemoryEnv) creates a new Slice when reading. If all the bytes for the read are in the first block then the Slice points to the private block data in FileState and is not copied to the |scratch| buffer. A recent change allows files in InMemEnv to be overwritten which deletes these blocks and in this case can result in a Slice having a dangling pointer. This change fixes this bug by always copying to the |scratch| buffer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=239301930
Diffstat (limited to 'helpers')
-rw-r--r--helpers/memenv/memenv.cc7
1 files changed, 0 insertions, 7 deletions
diff --git a/helpers/memenv/memenv.cc b/helpers/memenv/memenv.cc
index b78a998..ff384e4 100644
--- a/helpers/memenv/memenv.cc
+++ b/helpers/memenv/memenv.cc
@@ -82,13 +82,6 @@ class FileState {
assert(offset / kBlockSize <= std::numeric_limits<size_t>::max());
size_t block = static_cast<size_t>(offset / kBlockSize);
size_t block_offset = offset % kBlockSize;
-
- if (n <= kBlockSize - block_offset) {
- // The requested bytes are all in the first block.
- *result = Slice(blocks_[block] + block_offset, n);
- return Status::OK();
- }
-
size_t bytes_to_copy = n;
char* dst = scratch;