uutils / uutils/coreutils

cp: --sparse=always panics on 32-bit when the source is larger than 4 GiB

Open Beginner friendly
#12,647 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - cp
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.