Skip to content

Commit

Permalink
Make range check more accurate, and add comment why it is not useless
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Feb 7, 2024
1 parent 51cb026 commit 9c07a01
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ pub(crate) fn parse_rfc3339<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseRes
}

let offset = try_consume!(scan::timezone_offset(s, |s| scan::char(s, b':'), true, false, true));
const MAX_RFC3339_OFFSET: i32 = 86_400;
// This range check is similar to the one in `FixedOffset::east_opt`, so it would be redundant.
// But it is possible to read the offset directly from `Parsed`. We want to only successfully
// populate `Parsed` if the input is fully valid RFC 3339.
// Max for the hours field is `23`, and for the minutes field `59`.
const MAX_RFC3339_OFFSET: i32 = (23 * 60 + 59) * 60;
if !(-MAX_RFC3339_OFFSET..=MAX_RFC3339_OFFSET).contains(&offset) {
return Err(OUT_OF_RANGE);
}
Expand Down

0 comments on commit 9c07a01

Please sign in to comment.