mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							af3b15ef10
						
					
				
				
					commit
					4ab9cd7cf2
				
			@@ -1395,7 +1395,7 @@ class Timestamp(markdown.inlinepatterns.Pattern):
 | 
				
			|||||||
        time_input_string = match.group("time")
 | 
					        time_input_string = match.group("time")
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            timestamp = dateutil.parser.parse(time_input_string, tzinfos=common_timezones)
 | 
					            timestamp = dateutil.parser.parse(time_input_string, tzinfos=common_timezones)
 | 
				
			||||||
        except ValueError:
 | 
					        except (ValueError, OverflowError):
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                timestamp = datetime.fromtimestamp(float(time_input_string), tz=timezone.utc)
 | 
					                timestamp = datetime.fromtimestamp(float(time_input_string), tz=timezone.utc)
 | 
				
			||||||
            except ValueError:
 | 
					            except ValueError:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -844,6 +844,13 @@
 | 
				
			|||||||
      "expected_output": "<p>Let's meet at <time datetime=\"2017-06-05T22:30:00Z\">1496701800</time>.</p>",
 | 
					      "expected_output": "<p>Let's meet at <time datetime=\"2017-06-05T22:30:00Z\">1496701800</time>.</p>",
 | 
				
			||||||
      "text_content": "Let's meet at 1496701800."
 | 
					      "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",
 | 
					      "name": "tex_inline",
 | 
				
			||||||
      "input": "$$1 \\oplus 0 = 1$$",
 | 
					      "input": "$$1 \\oplus 0 = 1$$",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user