Commit e1812c07 authored by Leonid Baraz's avatar Leonid Baraz Committed by Chromium LUCI CQ

Fix reading bug in StorageQueue.

Bug was detected while working on stress test:
When part of the data is available and we want to read more,
we need to start not from initial 'pos' but shift to the position
after the available data! The original code always started to read
from the initial position - thus reading some data twice.

Also some cleanup done.

BUG: b:177439641
Change-Id: I59c9d36f97d2a7193ff0d211c61f5afb7cf2d60b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626102Reviewed-by: default avatarZach Trudo <zatrudo@google.com>
Commit-Queue: Leonid Baraz <lbaraz@chromium.org>
Auto-Submit: Leonid Baraz <lbaraz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843284}
parent 35e8309c
......@@ -72,7 +72,7 @@ void EncryptionModule::EncryptRecord(
encrypted_record.mutable_encrypted_wrapped_record()->assign(record.begin(),
record.end());
// encryption_info is not set.
std::move(cb).Run(encrypted_record);
std::move(cb).Run(std::move(encrypted_record));
return;
}
......
......@@ -366,8 +366,8 @@ Status StorageQueue::ScanLastFile() {
read_result.ValueOrDie().data(), header.record_size);
if (header.record_hash != actual_record_hash) {
LOG(ERROR) << "Hash mismatch, seq=" << header.record_sequencing_id
<< " expected_hash=" << std::hex << actual_record_hash
<< " actual_hash=" << std::hex << header.record_hash;
<< " actual_hash=" << std::hex << actual_record_hash
<< " expected_hash=" << std::hex << header.record_hash;
break;
}
// Everything looks all right. Advance the sequencing id.
......@@ -1410,8 +1410,10 @@ StatusOr<base::StringPiece> StorageQueue::SingleFile::Read(
data_start_ = 0;
}
size_t actual_size = data_end_ - data_start_;
pos += actual_size;
while (actual_size < size) {
// Read as much as possible.
DCHECK_LT(data_end_, buffer_size_);
const int32_t result =
handle_->Read(pos, reinterpret_cast<char*>(buffer_.get() + data_end_),
buffer_size_ - data_end_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment