[Bug]: hl panics on a relative --since or --until too far from now

Open Beginner friendly
#1,908 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
87/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cli

Research direction

Read src/timeparse.rs at relative_past and relative_future, then check how their callers convert None into Error::UnrecognizedTime. Replace the overflowing time arithmetic with checked operations and verify that extreme --since and --until values return an error instead of panicking.

Written by the indexing model from the issue text.

Description

bug

Observed

A relative time that reaches past the range of dates that hl can represent makes hl panic instead of reporting an error:

$ echo '{"ts":"2024-01-01T00:00:00Z","msg":"x"}' | hl --since -300000y -P
thread 'run' panicked at src/timeparse.rs:28:18:
`DateTime - TimeDelta` overflowed

--until +300000y does the same with +.

Expected

An error saying the time is out of range, as for any other value that --since and --until don't accept. A crash is a bug whatever the spec says. No spec covers relative times: specs/003-structured-logs/spec.md mentions --since and --until only for the format they take.

Where

relative_past and relative_future at src/timeparse.rs:25-41 add the duration to Utc::now() with the - and + operators of chrono, which panic on overflow. checked_sub_signed and checked_add_signed return None instead, which the callers already turn into Error::UnrecognizedTime.

clippy's unchecked_time_subtraction lint, enabled for #1890, covers only the std Instant and Duration types, so it doesn't catch this.

Dominant language
Rust
Stars
3.3k
Forks
67
Avg merge
3h 4m
Merged PRs (30d)
107

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pamburus/hl

All issues in pamburus/hl

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.