]> granicus.if.org Git - python/commitdiff
Issue #26709: Fixed Y2038 problem in loading binary PLists.
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 8 Apr 2016 12:00:02 +0000 (15:00 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 8 Apr 2016 12:00:02 +0000 (15:00 +0300)
Lib/plistlib.py
Lib/test/test_plistlib.py
Misc/NEWS

index b9946fd313af0d67fddb74c1d0022f803f518ad6..a39151fb0beb7bcfa8da68f8e3934d7120e83a89 100644 (file)
@@ -685,7 +685,7 @@ class _BinaryPlistParser:
             f = struct.unpack('>d', self._fp.read(8))[0]
             # timestamp 0 of binary plists corresponds to 1/1/2001
             # (year of Mac OS X 10.0), instead of 1/1/1970.
-            return datetime.datetime.utcfromtimestamp(f + (31 * 365 + 8) * 86400)
+            return datetime.datetime(2001, 1, 1) + datetime.timedelta(seconds=f)
 
         elif tokenH == 0x40:  # data
             s = self._get_size(tokenL)
index fef9f3997237e1b5dd9275cefe028e9da7452161..f0e9e5a9ea3dba182dd8219326f76568624f02ac 100644 (file)
@@ -428,6 +428,15 @@ class TestPlistlib(unittest.TestCase):
                 b'\x00\x00\x00\x00\x00\x00\x00\x13')
         self.assertEqual(plistlib.loads(data), {'a': 'b'})
 
+    def test_large_timestamp(self):
+        # Issue #26709: 32-bit timestamp out of range
+        for ts in -2**31-1, 2**31:
+            with self.subTest(ts=ts):
+                d = (datetime.datetime.utcfromtimestamp(0) +
+                     datetime.timedelta(seconds=ts))
+                data = plistlib.dumps(d, fmt=plistlib.FMT_BINARY)
+                self.assertEqual(plistlib.loads(data), d)
+
 
 class TestPlistlibDeprecated(unittest.TestCase):
     def test_io_deprecated(self):
index 7027b30c7172e96afd99ef37ea1a3cfccedbfe32..bd482851801370ab68b464c09eaa11034446754c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -99,6 +99,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #26709: Fixed Y2038 problem in loading binary PLists.
+
 - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our
   own SIGWINCH handler.  Patch by Eric Price.