uutils / uutils/coreutils

wc: Arithmetic overflow on large files

Open
#11,209 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - wc
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

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.

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

The issue names the wc command and provides a sparse-file reproduction, but no source files or tests. Start by running the reproduction and locating wc's cumulative byte-count path. Done means matching GNU behavior: saturate at u64::MAX, report a count-overflow diagnostic on stderr, and exit with status 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.