Skip to content

fix(fileio): guard ratio progress display against divide-by-zero on empty input - #4742

Open
rootkiller6788 wants to merge 1 commit into
facebook:devfrom
rootkiller6788:fix-lzma-frame-divide-by-zero
Open

fix(fileio): guard ratio progress display against divide-by-zero on empty input#4742
rootkiller6788 wants to merge 1 commit into
facebook:devfrom
rootkiller6788:fix-lzma-frame-divide-by-zero

Conversation

@rootkiller6788

Copy link
Copy Markdown

Problem

When compressing an empty input with the xz/lzma (or gzip/lz4) format, the progress display divides by inFileSize, which is 0 for an empty file:

Read : 0 / 0 MB ==> inf%

This is a divide-by-zero (the CLI prints inf%, and nan% in related configurations) in FIO_compressLzmaFrame. The identical unguarded expression also exists in FIO_compressGzFrame and FIO_compressLz4Frame.

Fix

Guard the denominator so the ratio is computed only when inFileSize != 0, and display 0.00% otherwise:

inFileSize ? (double)outFileSize/(double)inFileSize*100 : 0

Applied consistently to the gzip, lzma/xz, and lz4 frame compressors.

Verification

Reproduced against the real code path (CLI built with lzma support):

  • Before: zstd --format=xz -vv empty.txt prints Read : 0 / 0 MB ==> inf%
  • After: the same command prints Read : 0 / 0 MB ==> 0.00%

Non-empty inputs are unaffected (the ternary falls through to the normal ratio).

Closes #4393

@meta-cla meta-cla Bot added the CLA Signed label Aug 21, 2026
@rootkiller6788
rootkiller6788 marked this pull request as ready for review August 26, 2026 15:10
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.

Potential Divide-by-zero in function FIO_compressLzmaFrame

1 participant