Skip to content

fix: reject out-of-range timeout values before deadline construction - #1131

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
IG-ABHINAV:pr-1124-timeout-bounds
Nov 14, 2026
Merged

LunaStev merged 1 commit into
wavefnd:masterfrom
IG-ABHINAV:pr-1124-timeout-bounds

Conversation

@IG-ABHINAV

Copy link
Copy Markdown
Contributor

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 u64 seconds with no representability bound: freebsd providers --boot-timeout/--case-timeout/--command-timeout, exec --timeout, and test|corpus --timeout. Console then built boot and expect deadlines with unchecked Instant addition, so a syntactically valid integer such as 18446744073709551615 panicked with "overflow when adding duration to instant". The provider also derived the QEMU run timeout with panicking Duration operators.

How it works

  • wave_tools::cli::timeout is the single parse boundary for every timeout flag; values above MAX_TIMEOUT_SECONDS (u32::MAX seconds) fail with timeout must be at most ... seconds. One shared helper covers all flags rather than one fix per flag.
  • Console builds deadlines with Instant::checked_add through checked_deadline and now returns Result (Console::new became Result<Self>), so direct library use with Duration::from_secs(u64::MAX) returns timeout is too large for a deadline instead of panicking.
  • The derived provider VM timeout uses checked_add/saturating_mul instead of panicking Duration operators.
  • Zero keeps its existing per-command meaning: the FreeBSD provider still rejects it (timeouts must be positive) and exec/test still time out immediately.
  • Normal timeout behavior is unchanged for defaults, boundaries and in-range values.

Judgment call: placement of the bound

MAX_TIMEOUT_SECONDS = u32::MAX (about 136 years): comfortably representable by Instant::checked_add on all supported platforms, far beyond any realistic timeout, and it keeps every derived Duration computation inside u64 seconds. The bound lives in the shared cli::timeout helper used by all timeout flags; Console still 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).
  • Full cargo clippy --locked -p wave-tools --all-targets -- -D warnings fails 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: 3 byte_char_slices in tools/src/cases.rs:126, tools/src/package.rs:861, tools/src/wasm.rs:99 and 3 manual_is_multiple_of in utils/src/wson/mod.rs:409. Proven pre-existing by git stash -u and rerunning the identical command on the clean tree: identical sorted error lists.

Not run: meson test -C build-tools --suite tooling and build-tools/wave-tools maintain format --check - the build-tools harness is not present in this checkout; rustfmt was run instead.

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 LunaStev 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.

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.

@LunaStev
LunaStev merged commit ec281e6 into wavefnd:master Nov 14, 2026
50 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.

Reject out-of-range timeout values before constructing overflowing deadlines

2 participants