dd: derive the count_bytes read budget from bytes read#13435
Open
relative23 wants to merge 7 commits into
Open
dd: derive the count_bytes read budget from bytes read#13435relative23 wants to merge 7 commits into
relative23 wants to merge 7 commits into
Conversation
relative23
force-pushed
the
dd-count-bytes-loop-bsize
branch
from
July 17, 2026 19:17
4d451be to
136f5a9
Compare
calc_loop_bsize computed the remaining byte budget for
count=N iflag=count_bytes from the bytes written so far, while
below_count_limit gates the copy loop on bytes read. A conversion that
writes more than it reads (conv=block record expansion, conv=sync
padding of partial reads) pushes the written total past the limit while
the read total is still below it, and the u128 subtraction underflowed:
a panic in debug builds ('attempt to subtract with overflow' in
calc_loop_bsize), and a wrapped huge value in release builds that
unlocked a full-sized read on every following iteration, silently
overshooting the count limit.
Derive the remaining budget from the bytes read instead, matching
below_count_limit and the documented semantics of count_bytes
(saturating, so an inconsistency degrades to a zero-sized read instead
of wrapping), and drop the now-unused WriteStat parameter.
relative23
force-pushed
the
dd-count-bytes-loop-bsize
branch
from
July 18, 2026 13:00
136f5a9 to
c2c13db
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
|
GNU testsuite comparison: |
sylvestre
reviewed
Jul 21, 2026
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.
Fixes #13434.
calc_loop_bsizeused bytes written to calculate the remaining input budget forcount=N iflag=count_bytes. Expanding conversions could make the subtraction underflow: debug builds panicked, while release builds read 1,024 input bytes forcount=1000.Use
rstat.bytes_totalwith saturating subtraction. The regression test verifies that only the first 1,000 input bytes are converted.Validation
cargo test -p uu_dd