Skip to content

fix: division by zero in zstdcli_trace - #4761

Open
VirajMishra1 wants to merge 1 commit into
facebook:devfrom
VirajMishra1:fix-cli-trace-div-zero
Open

fix: division by zero in zstdcli_trace#4761
VirajMishra1 wants to merge 1 commit into
facebook:devfrom
VirajMishra1:fix-cli-trace-div-zero

Conversation

@VirajMishra1

Copy link
Copy Markdown

In programs/zstdcli_trace.c, the ratio calculation divides uncompressedSize by compressedSize without guarding against compressedSize == 0. This causes a floating-point division by zero when --trace is used with inputs that produce zero compressed bytes.

Line 84 already guards duration with a ternary for the same reason. This fix applies the same pattern to the ratio calculation on line 85: when compressedSize is 0, ratio is set to 0.0 instead of dividing.

This matches the approach suggested by the reviewer on the prior attempt (#4379).

Fixes #4368

Guard against division by zero when trace data has zero-valued
denominators. This can occur when --trace is used with certain inputs.

Fixes facebook#4368
@meta-cla meta-cla Bot added the CLA Signed label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible division by zero in zstdcli_trace.c

1 participant