Repository navigation
Conversation
xtqqczze
reviewed
Nov 29, 2026
| fn hash_update(&mut self, input: &[u8]) { | ||
| self.digest.update(input); | ||
| self.size += input.len(); | ||
| self.size += input.len() as u64; |
Collaborator
There was a problem hiding this comment.
Suggested change
| self.size += input.len() as u64; | |
| self.size += input.len().into(); |
Please use .into() instead of an as cast where possible, as it provides safer type conversions.
Collaborator
There was a problem hiding this comment.
Actually, .into() doesn't work here. You'd need to use u64::try_from(input.len()).unwrap(), which is a bit cumbersome given that the conversion is infallible on all supported platforms.
limadog9
force-pushed
the
fix/cksum-32bit-length-16994
branch
from
November 29, 2026 23:45
5ae2602 to
1a4d5f0
Compare
xtqqczze
reviewed
Nov 30, 2026
| fn hash_update(&mut self, input: &[u8]) { | ||
| self.digest.update(input); | ||
| self.size += input.len(); | ||
| self.size += u64::try_from(input.len()).expect("slice length fits in u64"); |
Collaborator
There was a problem hiding this comment.
Suggested change
| self.size += u64::try_from(input.len()).expect("slice length fits in u64"); | |
| self.size += u64::try_from(input.len()).unwrap_or(u64::MAX); |
I guess this is slightly less cumbersome than using expect.
limadog9
force-pushed
the
fix/cksum-32bit-length-16994
branch
from
November 30, 2026 00:19
1a4d5f0 to
99df3bc
Compare
xtqqczze
reviewed
Nov 30, 2026
|
|
||
| // Print the sum | ||
| let block_size = | ||
| u64::try_from(options.algo_kind.bitlen()).expect("legacy checksum sizes fit in u64"); |
Collaborator
There was a problem hiding this comment.
Suggested change
| u64::try_from(options.algo_kind.bitlen()).expect("legacy checksum sizes fit in u64"); | |
| u64::try_from(options.algo_kind.bitlen()).unwrap_or(u64::MAX); |
Use u64 for the length folded into the POSIX CRC and keep the byte count returned by io::copy when formatting legacy checksums. A 32-bit build previously reported the same CRC and length for 17 zero bytes and for 4 GiB plus 17 zero bytes. Use checked conversions for slice lengths and legacy block sizes. Rust provides TryFrom<usize> for u64. Exercise the CRC crossing the 4 GiB boundary and the printed size without hashing a multi-gigabyte fixture in the test suite. Closes uutils#16994
limadog9
force-pushed
the
fix/cksum-32bit-length-16994
branch
from
November 30, 2026 02:42
99df3bc to
d9ac1a9
Compare
This branch has not been deployed
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.
Keep the full input length when computing the POSIX CRC and printing the byte count. Add regression tests for the 4 GiB boundary.
Verified the 32-bit build against GNU cksum using the files from the issue.
Closes #16994