Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/flb_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct flb_zstd_decompression_context {
ZSTD_DCtx *dctx;
};

#define FLB_ZSTD_DEFAULT_CHUNK 64 * 1024 /* 64 KB buffer */
#define FLB_ZSTD_DEFAULT_CHUNK (64 * 1024) /* 64 KB buffer */
#define FLB_ZSTD_DECOMPRESS_MAX (100 * 1024 * 1024) /* 100 MB limit */

int flb_zstd_compress(void *in_data, size_t in_len, void **out_data, size_t *out_len)
{
Expand Down Expand Up @@ -104,7 +105,16 @@ static int zstd_uncompress_unknown_size(void *in_data, size_t in_len, void **out

/* check if we need more space */
if (output.pos == out_size) {
if (out_size >= FLB_ZSTD_DECOMPRESS_MAX) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow exact-size unknown zstd frames

For frames with ZSTD_CONTENTSIZE_UNKNOWN, this rejects a valid payload whose decompressed size is exactly FLB_ZSTD_DECOMPRESS_MAX: after the final ZSTD_decompressStream() call fills the 100 MB buffer, ret can already be 0, but this check runs before the existing ret == 0 completion check and returns failure. Known-size frames of exactly 100 MB are accepted by the new size > FLB_ZSTD_DECOMPRESS_MAX guard, so the limit is inconsistent and unknown-size inputs at the documented maximum are unnecessarily dropped.

Useful? React with 👍 / 👎.

flb_error("[zstd] maximum decompression size reached (~100 MB)");
flb_free(buf);
ZSTD_freeDCtx(dctx);
return -1;
}
out_size *= 2;
if (out_size > FLB_ZSTD_DECOMPRESS_MAX) {
out_size = FLB_ZSTD_DECOMPRESS_MAX;
}
tmp = flb_realloc(buf, out_size);
if (!tmp) {
flb_errno();
Expand Down Expand Up @@ -146,6 +156,12 @@ int flb_zstd_uncompress(void *in_data, size_t in_len, void **out_data, size_t *o
return ret;
}

if (size > FLB_ZSTD_DECOMPRESS_MAX) {
flb_error("[zstd] maximum decompression size is %d bytes",
FLB_ZSTD_DECOMPRESS_MAX);
return -1;
}

buf = flb_malloc(size);
if (!buf) {
flb_errno();
Expand Down
Loading