diff --git a/util/aligned_buffer.h b/util/aligned_buffer.h index 0024e4df4..2201b4877 100644 --- a/util/aligned_buffer.h +++ b/util/aligned_buffer.h @@ -121,6 +121,7 @@ public: ~static_cast(alignment_ - 1)); if (copy_data) { + assert(bufstart_ + copy_offset + copy_len <= bufstart_ + cursize_); memcpy(new_bufstart, bufstart_ + copy_offset, copy_len); cursize_ = copy_len; } else { diff --git a/util/file_reader_writer.cc b/util/file_reader_writer.cc index 127a19475..e8b03af49 100644 --- a/util/file_reader_writer.cc +++ b/util/file_reader_writer.cc @@ -672,7 +672,14 @@ Status FilePrefetchBuffer::Prefetch(RandomAccessFileReader* reader, chunk_len = buffer_len_ - chunk_offset_in_buffer; assert(chunk_offset_in_buffer % alignment == 0); assert(chunk_len % alignment == 0); - copy_data_to_new_buffer = true; + assert(chunk_offset_in_buffer + chunk_len <= + buffer_offset_ + buffer_len_); + if (chunk_len > 0) { + copy_data_to_new_buffer = true; + } else { + // this reset is not necessary, but just to be safe. + chunk_offset_in_buffer = 0; + } } }