Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some panics found by afl.rs #309

Closed
StevenJiang1110 opened this issue Jan 24, 2021 · 5 comments · May be fixed by comit-network/comit-rs#3529
Closed

Some panics found by afl.rs #309

StevenJiang1110 opened this issue Jan 24, 2021 · 5 comments · May be fixed by comit-network/comit-rs#3529
Assignees
Labels
A-core Area: anything not otherwise covered C-bug Category: bug in current code

Comments

@StevenJiang1110
Copy link

I have used afl.rs to fuzz this crate, and I found several cases will crash. The version I work on is version 0.2.24.

There are 2 about unreachable.

let date_ = time::Date::try_from_ymd(-36 ,11 ,1).unwrap();
let _ = time::Date::weekday(date_);
let date_ = time::Date::try_from_yo(-26 ,96).unwrap();
let _ = time::Date::weekday(date_);

And there are several about arithmetic overflow.

let _ = time::UtcOffset::west_minutes(32768);
let _ = time::util::weeks_in_year(-102);
let date_ = time::Date::try_from_yo(-31 ,136).unwrap();
let date2_ = time::Date::next_day(date_);
let _ = time::Date::iso_year_week(date2_);
let date_ = time::Date::try_from_yo(-60, 64).unwrap();
let date2_ = time::Date::previous_day(date_);
let _ = time::Date::week(date2_);
let date_ = time::Date::try_from_yo(-208 ,99).unwrap();
let date2_ = time::Date::try_with_hms_milli(date_, 22, 48,48 ,48).unwrap();
let _ = time::PrimitiveDateTime::week(date2_);

I hope you can check if these are really bugs that need to be fixed. Thanks a lot.

@jhpratt
Copy link
Member

jhpratt commented Jan 24, 2021

I'll verify these once I'm on my laptop, but on the assumption everything you've said is true, these are mostly bugs. The only one that would not be is the construction of the UtcOffset with an out of bounds minute value; this is explicitly mentioned in the documentation, so a panic is valid behavior.

Would you mind sharing the code used to find these? I've never used a fuzzer myself. This would also let me run it on the current head, where significant changes have taken place across the board.

@jhpratt
Copy link
Member

jhpratt commented Jan 24, 2021

Verifying the following as bugs in 0.2.24:

  • date!(-36-11-01).weekday()
  • date!(-26-96).weekday()
  • util::weeks_in_year(-102)
  • date!(-31-137).weekday()
  • date!(-31-137).week()
  • date!(-60-63).iso_year_week()
  • date!(-208-99).week()

I'll be investigating these further, of course. First up is to see if these bugs exist on main; I know one won't, as I (apparently incorrectly) assumed valid data. Needless to say this should be interesting.

@jhpratt jhpratt added A-core Area: anything not otherwise covered C-bug Category: bug in current code labels Jan 24, 2021
@jhpratt jhpratt self-assigned this Jan 24, 2021
jhpratt added a commit that referenced this issue Jan 25, 2021
This simple change fixes all reported invalid values.
@jhpratt
Copy link
Member

jhpratt commented Jan 25, 2021

Fixed in 0540d19.

@jhpratt jhpratt closed this as completed Jan 25, 2021
@jhpratt
Copy link
Member

jhpratt commented Jan 25, 2021

v0.2.25 has been released with this patch. I'd also like to report that this issue does not exist on main.

@StevenJiang1110
Copy link
Author

Thanks for your prompt reply. That's very helpful.
I would like to issue a pr about the fuzzing codes to find the bugs I found(I'm working on ddl now, so maybe several days later). They are using afl.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment