Skip to content

fs: reject durations like 300y that overflow instead of wrapping - #10129

Merged
ncw merged 1 commit into
rclone:masterfrom
kevin9327:fix-duration-suffix-overflow
Oct 20, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
kevin9327:fix-duration-suffix-overflow

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What does this change do?

fs.ParseDuration already rejects multi-unit durations that overflow time.Duration (300y1d → "too long", and there's a test for that). Single-suffix durations skipped the check, though. parseDurationSuffixes multiplied and converted with no bounds check, so 300y, -300y or 1e10d were accepted and wrapped to -2562047h47m16.854775808s.

In practice, --max-age 300y (or --max-age 1000y as "anything") gave no error. It set ModTimeFrom = now - (negative), which is ~292 years in the future, so the filter silently excluded every file.

The fix adds the same >= math.MaxInt64 check to parseDurationSuffixes, so these values return an error now.

Tests: I added 300y, -300y and 1e10d to TestParseDuration. They fail before the change and pass after. go build ./... passes, and go test ./fs/... passes except fs/logger (TestCheckVsSync.txtar), which fails the same way on unmodified master in my environment.

Linked issue

None. This is a small obvious bug fix I found while reading the code.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

Prepared with AI assistance. I reviewed, built and tested the change myself.

ParseDuration checked for overflow in multi-unit durations such as
300y1d but not in single-suffix ones, so --max-age 300y silently
became a large negative duration, which moved the filter's
ModTimeFrom into the future and excluded every file.
@kevin9327
kevin9327 requested a review from ncw as a code owner October 18, 2026 19:52

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :-)

@ncw
ncw merged commit 40139a7 into rclone:master Oct 20, 2026
9 checks passed
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