fix(fileio): guard ratio progress display against divide-by-zero on empty input - #4742
Open
rootkiller6788 wants to merge 1 commit into
Open
fix(fileio): guard ratio progress display against divide-by-zero on empty input#4742rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
rootkiller6788
marked this pull request as ready for review
August 26, 2026 15:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:This is a divide-by-zero (the CLI prints
inf%, andnan%in related configurations) inFIO_compressLzmaFrame. The identical unguarded expression also exists inFIO_compressGzFrameandFIO_compressLz4Frame.Fix
Guard the denominator so the ratio is computed only when
inFileSize != 0, and display0.00%otherwise:Applied consistently to the gzip, lzma/xz, and lz4 frame compressors.
Verification
Reproduced against the real code path (CLI built with lzma support):
zstd --format=xz -vv empty.txtprintsRead : 0 / 0 MB ==> inf%Read : 0 / 0 MB ==> 0.00%Non-empty inputs are unaffected (the ternary falls through to the normal ratio).
Closes #4393