Repository navigation
fix: reject out-of-range timeout values before deadline construction - #1131
Conversation
Timeout options parsed u64 seconds without a representability bound, so Console built boot and expect deadlines with unchecked Instant addition and panicked for syntactically valid input such as Duration::from_secs(u64::MAX). Parse every timeout flag through one shared boundary (cli::timeout) that rejects seconds above MAX_TIMEOUT_SECONDS as ordinary input errors, construct Console deadlines with Instant::checked_add (returning an error instead of panicking), and use checked Duration arithmetic for the derived provider VM timeout. Zero keeps its existing per-command meaning. Signed-off-by: IG-ABHINAV <IG-ABHINAV@users.noreply.github.com>
LunaStev
left a comment
There was a problem hiding this comment.
Reviewed exact head 2a549e540a392ac08f1a092891598cfdb6a97681. The shared timeout parser rejects excessive CLI values before deadline arithmetic; Console uses checked deadline construction, and the derived FreeBSD VM timeout is protected. Existing per-command zero-timeout behavior is retained.
Local validation with pinned Rust 1.89.0 passed all 64 wave-tools tests, full Cargo formatting, and all-target Clippy with warnings denied. The initial Unix socket fixture required local socket permission and passed with that permission; no native FreeBSD VM execution is claimed.
PR CI 43235716609 is completed/success for this exact head, with all 50 distinct jobs completed/success. The linked completed scope is #1124.
What
Reject out-of-range timeout values before any deadline is constructed, so CLI and library invalid input becomes an ordinary error instead of a panic.
Fixes #1124.
Why
Timeout options parse
u64seconds with no representability bound:freebsd providers --boot-timeout/--case-timeout/--command-timeout,exec --timeout, andtest|corpus --timeout. Console then built boot and expect deadlines with uncheckedInstantaddition, so a syntactically valid integer such as18446744073709551615panicked with "overflow when adding duration to instant". The provider also derived the QEMU run timeout with panickingDurationoperators.How it works
wave_tools::cli::timeoutis the single parse boundary for every timeout flag; values aboveMAX_TIMEOUT_SECONDS(u32::MAXseconds) fail withtimeout must be at most ... seconds. One shared helper covers all flags rather than one fix per flag.Consolebuilds deadlines withInstant::checked_addthroughchecked_deadlineand now returnsResult(Console::newbecameResult<Self>), so direct library use withDuration::from_secs(u64::MAX)returnstimeout is too large for a deadlineinstead of panicking.checked_add/saturating_mulinstead of panickingDurationoperators.timeouts must be positive) andexec/teststill time out immediately.Judgment call: placement of the bound
MAX_TIMEOUT_SECONDS = u32::MAX(about 136 years): comfortably representable byInstant::checked_addon all supported platforms, far beyond any realistic timeout, and it keeps every derivedDurationcomputation insideu64seconds. The bound lives in the sharedcli::timeouthelper used by all timeout flags;Consolestill constructs deadlines with checked addition as defense in depth for direct library callers.Checks
cargo fmt --all --check- pass (exit 0).cargo test --locked -p wave-tools- pass: 52 passed, 0 failed across 13 test targets.cargo test --locked -p wave-tools timeout- pass: 5 passed, 0 failed (all new timeout tests: helper boundary/rejection, Console out-of-range, Console zero/boundary, exec CLI rejection, exec CLI boundary/normal).cargo clippy --locked -p wave-tools --all-targets --no-deps -- -D warnings -A clippy::byte_char_slices- pass (exit 0, 0 warnings).cargo clippy --locked -p wave-tools --all-targets -- -D warningsfails in this environment (local Rust 1.99 clippy rather than the pinned CI toolchain) with 6 pre-existing errors in files this PR does not touch: 3byte_char_slicesintools/src/cases.rs:126,tools/src/package.rs:861,tools/src/wasm.rs:99and 3manual_is_multiple_ofinutils/src/wson/mod.rs:409. Proven pre-existing bygit stash -uand rerunning the identical command on the clean tree: identical sorted error lists.Not run:
meson test -C build-tools --suite toolingandbuild-tools/wave-tools maintain format --check- the build-tools harness is not present in this checkout; rustfmt was run instead.