Repository navigation
fs: reject durations like 300y that overflow instead of wrapping - #10129
Merged
Merged
Conversation
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.
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change do?
fs.ParseDurationalready rejects multi-unit durations that overflowtime.Duration(300y1d→ "too long", and there's a test for that). Single-suffix durations skipped the check, though.parseDurationSuffixesmultiplied and converted with no bounds check, so300y,-300yor1e10dwere accepted and wrapped to-2562047h47m16.854775808s.In practice,
--max-age 300y(or--max-age 1000yas "anything") gave no error. It setModTimeFrom = now - (negative), which is ~292 years in the future, so the filter silently excluded every file.The fix adds the same
>= math.MaxInt64check toparseDurationSuffixes, so these values return an error now.Tests: I added
300y,-300yand1e10dtoTestParseDuration. They fail before the change and pass after.go build ./...passes, andgo test ./fs/...passes exceptfs/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
Prepared with AI assistance. I reviewed, built and tested the change myself.