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

Fix possible panic in NaiveDate::from_num_days_from_ce_opt #527

Closed
wants to merge 1 commit into from

Conversation

b3t33
Copy link

@b3t33 b3t33 commented Jan 19, 2021

Add some test including panic triggering example
NaiveDate::from_num_days_from_ce_opt(i32::MAX).
As the function already yields None for i32::Max - 365, this fix
does not change the behaviour, while preventing a panic.

Thanks for contributing to chrono!

  • Have you added yourself and the change to the changelog? (Don't worry
    about adding the PR number)
  • If this pull request fixes a bug, does it add a test that verifies that
    we can't reintroduce it?

@quodlibetor
Copy link
Contributor

Thanks for this! If you rebase on main the clippy lints should go away.

Just curious, did you actually run into this issue or did you just notice it?

Add some test including panic triggering example
`NaiveDate::from_num_days_from_ce_opt(i32::MAX)`.
As the function already yields `None` for `i32::Max - 365`, this fix
does not change the behaviour, while preventing a panic.
@quodlibetor
Copy link
Contributor

Actually I was able to rebase for you.

@b3t33
Copy link
Author

b3t33 commented Jan 22, 2021

Thanks for rebasing.
Well, actually using quickcheck 1.0 (combined with a very simplistic construction of NaiveDate) escalated this for me and inspecting the source revealed the problematic days + 365.

@pitdicker
Copy link
Collaborator

This fixes a potential panic, similar to those found in #1010.

@b3t33 Could you rebase this PR and target the 0.4.x branch?

#[test]
fn test_date_from_num_days_from_ce_opt() {
let ndays_from_ce = |days| NaiveDate::from_num_days_from_ce_opt(days);
ndays_from_ce(i32::MAX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these two checks be moved into test_date_from_num_days_from_ce below?
Also, why not check the return value of the closure ?

@djc
Copy link
Contributor

djc commented May 11, 2023

This was taken care of in #1052. Thanks for doing the work!

@djc djc closed this May 11, 2023
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.

None yet

5 participants