Skip to content

wc: Arithmetic overflow on large files #11209

@sr-ut

Description

@sr-ut

There is currently a discrepancy between uutils/wc and GNU coreutils/wc regarding large files.
When processing multiple extremely large (possibly sparse) files, the cumulative total can exceed the capacity of a 64-bit integer. Currently, uutils/wc panics in debug builds or wraps around in release builds, whereas GNU wc handles this gracefully by saturating at the maximum value and issuing a diagnostic error.

Steps to Reproduce

Using sparse files to simulate sizes exceeding
2**64−1

# Create a 2-exabyte sparse file
truncate -s 2E big
# Trigger overflow by summing multiple instances
uutils-wc -c big big big big big big big big big big

Current Behavior: Panic or silent wrap-around.
GNU Behavior: Prints a diagnostic wc: count overflow to stderr, saturates the count at u64::MAX, and exits with status 1.

I'd like to handle the problem. I would replace usize with u64 for the counters and check for overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions