Skip to content

Reject out-of-range --mtime/--atime/--ctime values instead of overflowing - #661

Closed
lee3Q wants to merge 2 commits into
bootandy:masterfrom
lee3Q:fix-time-filter-overflow
Closed

lee3Q wants to merge 2 commits into
bootandy:masterfrom
lee3Q:fix-time-filter-overflow

Conversation

@lee3Q

@lee3Q lee3Q commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

--mtime, --atime and --ctime compute days.abs() * DAY_SECONDS and subtract it from the current date with unchecked i64 arithmetic. For very large values (more than 106751991167300 days, or i64::MIN) a debug build panics ("attempt to multiply with overflow" / "attempt to negate with overflow"). In a release build I saw the arithmetic wrap and dust run with a nonsense filter and exit 0, instead of reporting an error.

This uses checked_abs / checked_mul / checked_sub and reuses the existing "Invalid value for time filter" message and exit 1 for those values. Values that were accepted before behave the same (5, +5, -5 checked by hand).

This only affects unrealistic input (10^14 days), so the benefit is small.

What I ran, on Linux x86_64 only, one machine:

  • on master 5ac179e: cargo test (all pass), cargo fmt --check, a new integration test fails without the change and passes with it
  • debug and release builds, run by hand with the values above
  • clippy shows no new warnings

Not tested: other OSes or architectures.

This patch and description were written by an AI assistant working for the account owner. It was built and tested as listed above, but no human has reviewed the diff. I added a small test in tests/test_flags.rs; it is easy to drop if you prefer not to have it.

@bootandy

Copy link
Copy Markdown
Owner

I don't think we need to worry about that now - lets deal with that when it becomes a problem in 292471208677 years.

@bootandy bootandy closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants