Skip to content

Commit eb3ded1

Browse files
thewillyhumanclaude
andcommitted
snappy: fix multi-chunk framed data silently dropped
After the frame parsing loop accumulates the total decompressed length in aggregated_data_length, the variable was incorrectly reset to zero before being used for the output buffer allocation. This caused the multi-chunk code path to skip allocation entirely, producing a NULL output buffer and zero length with a success return code — silently dropping all decompressed data. Remove the erroneous reset so the accumulated length is preserved and used for the aggregation buffer allocation. Also gate the allocation on result == 0 and free any allocated buffer on error, preventing a memory leak when a multi-chunk stream fails mid-way (e.g. checksum mismatch after one valid chunk). Signed-off-by: Gabriele Facundo <gabriele.facundo@cern.ch> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7800ae2 commit eb3ded1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/flb_snappy.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ int flb_snappy_uncompress_framed_data(char *in_data, size_t in_len,
302302
}
303303

304304
aggregated_data_buffer = NULL;
305-
aggregated_data_length = 0;
306305

307306
if (compressed_chunk_count == 1 &&
308307
uncompressed_chunk_count == 0 &&
@@ -322,7 +321,7 @@ int flb_snappy_uncompress_framed_data(char *in_data, size_t in_len,
322321
flb_free(chunk);
323322
}
324323
else {
325-
if (aggregated_data_length > 0) {
324+
if (aggregated_data_length > 0 && result == 0) {
326325
aggregated_data_buffer = flb_calloc(aggregated_data_length,
327326
sizeof(char));
328327

@@ -357,6 +356,12 @@ int flb_snappy_uncompress_framed_data(char *in_data, size_t in_len,
357356
}
358357
}
359358

359+
if (result != 0) {
360+
flb_free(aggregated_data_buffer);
361+
aggregated_data_buffer = NULL;
362+
aggregated_data_offset = 0;
363+
}
364+
360365
*out_data = (char *) aggregated_data_buffer;
361366
*out_len = aggregated_data_offset;
362367

0 commit comments

Comments
 (0)