File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -607,6 +607,9 @@ def _get_parsed_value(
607607
608608 offset = ((int (off_hour ) * 60 ) + int (off_minute )) * 60
609609
610+ if abs (offset ) >= 24 * 3600 :
611+ raise ValueError ("Invalid date" )
612+
610613 if negative :
611614 offset = - 1 * offset
612615
Original file line number Diff line number Diff line change @@ -250,6 +250,9 @@ def parse_iso8601(
250250
251251 offset = ((int (off_hour ) * 60 ) + int (off_minute )) * 60
252252
253+ if abs (offset ) >= 24 * 3600 :
254+ raise ParserError (f"Invalid date string: { text } " )
255+
253256 if negative :
254257 offset = - 1 * offset
255258
Original file line number Diff line number Diff line change @@ -72,6 +72,13 @@ def test_from_format_with_invalid_padded_day():
7272 pendulum .from_format ("Apr 2 12:00:00 2020 GMT" , "MMM DD HH:mm:ss YYYY z" )
7373
7474
75+ def test_from_format_with_out_of_range_offset ():
76+ with pytest .raises (ValueError ):
77+ pendulum .from_format ("1975-05-21 22:32:11 +9959" , "YYYY-MM-DD HH:mm:ss ZZ" )
78+ with pytest .raises (ValueError ):
79+ pendulum .from_format ("1975-05-21 22:32:11 +24:00" , "YYYY-MM-DD HH:mm:ss Z" )
80+
81+
7582@pytest .mark .parametrize (
7683 "text,fmt,expected,now" ,
7784 [
Original file line number Diff line number Diff line change @@ -153,6 +153,14 @@ def test_parse_iso8601_invalid():
153153 with pytest .raises (ValueError ):
154154 parse_iso8601 ("2009-05-19 14:39:22+0:6:00" )
155155
156+ # Offset out of range (>= 24h)
157+ with pytest .raises (ValueError ):
158+ parse_iso8601 ("2016-10-16T12:34:56+99:59" )
159+ with pytest .raises (ValueError ):
160+ parse_iso8601 ("2016-10-16T12:34:56-2400" )
161+ with pytest .raises (ValueError ):
162+ parse_iso8601 ("2016-10-16T12:34:56+2400" )
163+
156164 # Missing time separator
157165 with pytest .raises (ValueError ):
158166 parse_iso8601 ("2009-05-1914:39" )
You can’t perform that action at this time.
0 commit comments