cp: --sparse=always panics on 32-bit when the source is larger than 4 GiB
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
sparse_copy() in src/uu/cp/src/platform/linux.rs narrows the source size from u64 to usize with try_into().unwrap():
let size: usize = src_file.metadata()?.size().try_into().unwrap();
On a 32-bit target usize is 32 bits, so any source larger than usize::MAX (≈4 GiB) makes the unwrap() panic instead of copying.
Steps to reproduce
On a 32-bit target (e.g. i686-unknown-linux-gnu or armv7):
$ truncate -s 5G big # cheap 5 GiB sparse file
$ cp --reflink=never --sparse=always big copy
thread 'main' panicked at src/uu/cp/src/platform/linux.rs:170:
called `Result::unwrap()` on an `Err` value: TryFromIntError(())
GNU cp copies the file without error.
Expected
No panic, and no unwrap() (per the project's no-panic rule).
Reported by V12 (finding F-65899).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/uu/cp/src/platform/linux.rs at sparse_copy() and inspect the source-size conversion shown in the issue. Reproduce with a 5 GiB sparse file on a 32-bit target using cp --reflink=never --sparse=always. Done means the copy completes without a panic and the implementation has no unwrap() for this conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100