Pārlūkot izejas kodu

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
xry
cmumford pirms 5 gadiem
revīziju iesūtīja Victor Costan
vecāks
revīzija
ce399ac28a
1 mainītis faili ar 0 papildinājumiem un 7 dzēšanām
  1. +0
    -7
      helpers/memenv/memenv.cc

+ 0
- 7
helpers/memenv/memenv.cc Parādīt failu

@ -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;

Notiek ielāde…
Atcelt
Saglabāt