Compressor: make Compress size-aware, drop frames that don't fit
JFJochBitShuffleCompressor::Compress now takes a dest_size and returns a negative value when the compressed output would not fit, instead of writing past the destination buffer. The check is lazy: before each block it verifies the remaining space still covers that block's worst case (mirrored by the new MaxCompressedBlockSize helper, consistent with MaxCompressedSize so a dest sized to MaxCompressedSize never fails). On overflow the dest content is undefined - no rescue. The receiver uses this to compress directly into the writer buffer slot and drop just the oversized frame instead of pre-reserving the full worst-case image size next to the per-image CBOR metadata. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -240,7 +240,7 @@ TEST_CASE("JFJochCompressor_JFJochDecompressor_ZSTD","[ZSTD]") {
|
||||
|
||||
std::vector<char> tmp(x.GetPixelsNum() * sizeof(int32_t) * 4 + 12);
|
||||
|
||||
auto tmp_size = compressor.Compress(tmp.data(), image);
|
||||
auto tmp_size = compressor.Compress(tmp.data(), tmp.size(), image);
|
||||
tmp.resize(tmp_size);
|
||||
|
||||
std::vector<int32_t> output;
|
||||
@@ -262,7 +262,7 @@ TEST_CASE("JFJochCompressor_JFJochDecompressor_LZ4","[ZSTD]") {
|
||||
|
||||
std::vector<char> tmp(x.GetPixelsNum() * sizeof(int32_t) * 4 + 12);
|
||||
|
||||
auto tmp_size = compressor.Compress(tmp.data(), image);
|
||||
auto tmp_size = compressor.Compress(tmp.data(), tmp.size(), image);
|
||||
tmp.resize(tmp_size);
|
||||
|
||||
std::vector<int32_t> output;
|
||||
|
||||
Reference in New Issue
Block a user