Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown: Prevent OverflowError with large time integers.

Alex Vandiver4ab9cd7cf286
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index b3ff0cd6307..68ef2acad4a 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -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:
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index eeb95214dcf..e2ba52b97f8 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -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$$",