Skip to content

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

@sylvestre

Description

@sylvestre

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions