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

Đang mở Phù hợp với người mới
#1,908 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
87/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
cli

Hướng nghiên cứu

Đọc src/timeparse.rs tại relative_past và relative_future, rồi kiểm tra cách các hàm gọi chúng chuyển None thành Error::UnrecognizedTime. Thay phép tính thời gian gây tràn bằng các phép toán có kiểm tra và xác minh rằng các giá trị cực lớn của --since và --until trả về lỗi thay vì gây panic.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
3.3k
Fork
67
Merge trung bình
3 giờ 4 phút
Pull request đã merge (30 ngày)
107

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pamburus/hl

Tất cả issue của pamburus/hl

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.