Copilot commented on code in PR #67204:
URL: https://github.com/apache/doris/pull/67204#discussion_r3870206648
##########
be/src/load/group_commit/wal/wal_file_reader.cpp:
##########
@@ -92,18 +99,35 @@ Status WalFileReader::read_block(PBlock& block) {
if (block_len == 0) {
return Status::DataQualityError("fail to read wal {} ,block is empty",
_file_name);
}
- if (_offset == file_reader->size()) {
- LOG(WARNING) << "need read block with length=" << block_len << ", but
offset=" << _offset
- << " reached end of WAL (path=" << _file_name
- << ", size=" << file_reader->size() << ")";
+ const size_t remaining_bytes = file_size - _offset;
+ if (block_len > remaining_bytes) {
+ LOG(WARNING) << "ignore incomplete wal tail, path=" << _file_name
+ << ", file_size=" << file_size << ", read_offset=" <<
_offset
+ << ", block_bytes=" << block_len
+ << ", available_bytes=" << remaining_bytes;
return Status::EndOfFile("end of wal file");
}
// read block
std::string block_buf;
block_buf.resize(block_len);
RETURN_IF_ERROR(file_reader->read_at(_offset, {block_buf.c_str(),
block_len}, &bytes_read));
Review Comment:
`std::string::c_str()` returns a const pointer; passing it as a writable
buffer to `FileReader::read_at` relies on casting away const via `Slice` and
can be undefined behavior. Use `block_buf.data()` (C++20 in BE) to provide a
writable buffer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]