Skip to content

Commit 6da6722

Browse files
mugitya03jinyaoguo
authored andcommitted
compress: prevent divide-by-zero when no data is read (#37706)
If the first call to `loop_read()` returns 0 (no input), `total_in` remains 0, causing `total_out/total_in` to potential divide by zero. We add a check before logging the compression ratio to skip the percentage calculation when total_in is zero. Co-authored-by: jinyaoguo <[email protected]> (cherry picked from commit 2584f74) (cherry picked from commit 18a42e321d699e7f3ae46930fa070228d02774ed) (cherry picked from commit eaffe6679b6bcf6d5ba4d468332079a9ac82da43) (cherry picked from commit 93f677f) (cherry picked from commit cb57cbc)
1 parent 3b507fe commit 6da6722

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/basic/compress.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,12 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes, uint64_t *ret_unco
703703
if (ret_uncompressed_size)
704704
*ret_uncompressed_size = total_in;
705705

706-
log_debug("LZ4 compression finished (%" PRIu64 " -> %" PRIu64 " bytes, %.1f%%)",
707-
total_in, total_out,
708-
(double) total_out / total_in * 100);
706+
if (total_in == 0)
707+
log_debug("LZ4 compression finished (no input data)");
708+
else
709+
log_debug("LZ4 compression finished (%" PRIu64 " -> %" PRIu64 " bytes, %.1f%%)",
710+
total_in, total_out,
711+
(double) total_out / total_in * 100);
709712

710713
return COMPRESSION_LZ4;
711714
#else

0 commit comments

Comments
 (0)