markdown: Prevent OverflowError with large time integers.

`<time:1234567890123>` causes a "signed integer is greater than
maximum" exception from dateutil.parser; datetime also cannot handle
it ("year 41091 is out of range") but that is a ValueError which is
already caught.

Catch the OverflowError thrown by dateutil.
This commit is contained in:
Alex Vandiver 2024-01-05 14:38:08 +00:00 committed by Tim Abbott
parent af3b15ef10
commit 4ab9cd7cf2
2 changed files with 8 additions and 1 deletions

View File

@ -1395,7 +1395,7 @@ class Timestamp(markdown.inlinepatterns.Pattern):
time_input_string = match.group("time")
try:
timestamp = dateutil.parser.parse(time_input_string, tzinfos=common_timezones)
except ValueError:
except (ValueError, OverflowError):
try:
timestamp = datetime.fromtimestamp(float(time_input_string), tz=timezone.utc)
except ValueError:

View File

@ -844,6 +844,13 @@
"expected_output": "<p>Let's meet at <time datetime=\"2017-06-05T22:30:00Z\">1496701800</time>.</p>",
"text_content": "Let's meet at 1496701800."
},
{
"name": "timestamp_unix_overflow",
"input": "Let's meet at <time:1234567890123>.",
"expected_output": "<p>Let's meet at <span class=\"timestamp-error\">Invalid time format: 1234567890123</span>.</p>",
"marked_expected_output": "<p>Let's meet at <time datetime=\"+041091-11-25T05:02:03Z\">1234567890123</time>.</p>",
"text_content": "Let's meet at Invalid time format: 1234567890123."
},
{
"name": "tex_inline",
"input": "$$1 \\oplus 0 = 1$$",