[PATCH] util: fix crash converting an invalid future date to string

Kevin Gessner kevin at fogcreek.com
Fri Sep 23 10:45:57 CDT 2011


# HG changeset patch
# User Kevin Gessner <kevin at fogcreek.com>
# Date 1316793747 25200
# Node ID 74c597ca2fcf83e88c746c7d902b4152e6b818b8
# Parent  91dc8878f88857f01b86a99ad047400704b5fd7e
util: fix crash converting an invalid future date to string

Post-2038 timestamps cannot be handled on 32-bit architectures. Clamp
such dates to the maximum 32-bit timestamp.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -913,7 +913,12 @@
         minutes = abs(tz) // 60
         format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
         format = format.replace("%2", "%02d" % (minutes % 60))
-    s = time.strftime(format, time.gmtime(float(t) - tz))
+    try:
+        t = time.gmtime(float(t) - tz)
+    except ValueError:
+        # time was out of range
+        t = time.gmtime(sys.maxint)
+    s = time.strftime(format, t)
     return s
 
 def shortdate(date=None):


More information about the Mercurial-devel mailing list