You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible division by zero in zstdcli_trace.c #4368
PTime const durationNanos = endNanos > beginNanos ? endNanos - beginNanos : 0; states that 'durationNanos' will be either 'endNanos - beginNanos', if 'endNanos' is bigger, or zero otherwise
Next this function calls TRACE_log("compress", durationNanos, trace);
In TRACE_log, further, it passed to a equation, where possibly division by zero happens
static void TRACE_log(char const* method, PTime duration, ZSTD_Trace const* trace)
{
int level = 0;
int workers = 0;
double const ratio = (double)trace->uncompressedSize / (double)trace->compressedSize;
double const speed = ((double)trace->uncompressedSize * 1000) / (double)duration;
if (trace->params) {
...
double const speed = ((double)trace->uncompressedSize * 1000) / (double)duration; here, if 'durationNanos' was zero, will be a division by zero
Thanks for the report @Aruise! Looks like a bug. It will only be triggered if the user passes --trace on the command line, which I don't expect many people are doing, so the impact should be quite limited.
This appears to have been fixed already by #4464, which merged commit ae64545c6b6257c226dca6240be7b2d345d9bee5 (fixed a potential division by 0 in the cli trace unit). That PR modified programs/zstdcli_trace.c, and #4379 was later closed with the same note.
So I do not think a new fix PR is needed for this issue. It may be closable as completed by #4464.
Checked with Codex assistance; I verified #4379, #4464, and the merged commit metadata before commenting.
Activity
terrelln commentedon Apr 17, 2025
Thanks for the report @Aruise! Looks like a bug. It will only be triggered if the user passes
--traceon the command line, which I don't expect many people are doing, so the impact should be quite limited.Mrigankkh commentedon Apr 27, 2025
Hey, I'm interested in working on this issue. Would it be okay if I take it?"
terrelln commentedon Apr 30, 2025
@Mrigankkh absolutely!
Mrigankkh commentedon Apr 30, 2025
Awesome! On it!
Mrigankkh commentedon May 1, 2025
Created a Pull Request for the Bug Fix: #4379
mizoz commentedon Apr 28, 2026
Hi! I'd love to contribute. Could you assign this issue to me?
WilliamK112 commentedon Jun 18, 2026
This appears to have been fixed already by #4464, which merged commit
ae64545c6b6257c226dca6240be7b2d345d9bee5(fixed a potential division by 0 in the cli trace unit). That PR modifiedprograms/zstdcli_trace.c, and #4379 was later closed with the same note.So I do not think a new fix PR is needed for this issue. It may be closable as completed by #4464.
Checked with Codex assistance; I verified #4379, #4464, and the merged commit metadata before commenting.