fix(cli): reject out-of-range durations instead of overflowing - #3044
Merged
Conversation
parse_duration_to_ms multiplied the parsed number by its unit multiplier without a range check. A large --since value on `openshell logs` overflows i64: a debug build panics with "attempt to multiply with overflow", and a release build wraps to a nonsense log cutoff. Use checked_mul and return a diagnostic naming the offending input. Every in-range result is unchanged, and the largest accepted duration still leaves the caller's `now_ms - dur_ms` well inside i64. Signed-off-by: Nathan DeMoss <ndemoss28@gmail.com>
natedemoss
requested review from
a team,
derekwaynecarr,
mrunalp and
sjenning
as code owners
August 31, 2026 17:12
Collaborator
|
/ok to test 176401e |
johntmyers
approved these changes
Aug 31, 2026
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.
Summary
parse_duration_to_msmultiplied the parsed number by its unit multiplier without a range check, so a large--sincevalue onopenshell logsoverflowsi64. A debug build (whatscripts/bin/openshellruns) panics withattempt to multiply with overflow; a release build wraps and the CLI silently computes a nonsense log cutoff. This replaces the bare multiply withchecked_muland a diagnostic.Related Issue
No issue required: obvious localized bug fix, contained to one parsing helper in the CLI.
Changes
crates/openshell-cli/src/commands/common.rs:parse_duration_to_msuseschecked_muland returnsduration out of range: {s} (must fit in milliseconds as a 64-bit integer)instead of overflowing.Testing
mise run pre-commitpassesmiseand Docker are not installed on this workstation, so I ran the pre-commit steps individually rather than through the task:cargo fmt --all -- --check— clean.cargo test -p openshell-cli --lib— 239 passed, 0 failed, including the three new tests.python scripts/update_license_headers.py --check— 862 files, all headers present.cargo clippy -p openshell-cli --all-targets -- -D warnings— clean foropenshell-cli, but I had to add-A clippy::unused_asyncto get there. On Windows the#[cfg(not(unix))]connect_unixstub incrates/openshell-extension-core/src/transport.rs:185has no.awaitand tripsclippy::unused_async, failing the workspace lint beforeopenshell-cliis reached. That is pre-existing onmainand unrelated to this change; I left it alone rather than widen this PR. Happy to file it separately.Reproduction, on
main:openshell logs <sandbox> --since 9223372036854775807hpanics. After the change it reportsduration out of range.--since 30s|5m|1hresolves to the same cutoff before and after.The call site's
now_ms - dur_ms(run.rs:7056) cannot overflow once the multiply is bounded: the largest accepted value isi64::MAXrounded down to a whole multiplier, andnow_msis on the order of1.8e12, so the difference stays abovei64::MIN.No docs change: the
--sincesyntax documented indocs/sandboxes/manage-sandboxes.mdxis unchanged.Checklist
AI assistance: an agent explored the CLI parsing helpers, wrote the fix and tests, and ran the checks. I reviewed it and can explain it — the defect is the unchecked
num * multiplierat the end ofparse_duration_to_ms, its only caller is the--sincehandling inrun.rs, and the fix leaves every in-range result identical.