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) {
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