Skip to content

Commit 2d7163d

Browse files
committed
fix: file size check for zstd compression
Updates the file size check to correctly account for the accumulated input buffer size, preventing potential file overflow issues. Replaces a status check with a direct return of the status, simplifying the code.
1 parent e3f493b commit 2d7163d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/ulog/file/file_writer_zstd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class FileWriterZstd final : public FileWriterBase {
5959
}
6060

6161
Status Write(const void* data, const size_t length) override {
62-
if (file_->TellP() + ZSTD_compressBound(length) + zstd_header_size() > config_file_limit_size_) {
62+
if (file_->TellP() + ZSTD_compressBound(zstd_frame_in_ + length) + zstd_header_size() > config_file_limit_size_) {
6363
return Status::Full();
6464
}
6565

@@ -114,7 +114,7 @@ class FileWriterZstd final : public FileWriterBase {
114114

115115
if (mode == ZSTD_e_end || out_buffer_.size == out_buffer_.pos) {
116116
if (const auto status = file_->Write(out_buffer_.dst, out_buffer_.pos); !status) {
117-
return Status::IOError("Error writing to file");
117+
return status;
118118
}
119119
out_buffer_.pos = 0;
120120
}

0 commit comments

Comments
 (0)