diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-08-25 05:53:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-25 05:53:20 (GMT) |
commit | c47acc2bb1d0a3fb6dda14ced958d272fb2821a6 (patch) | |
tree | f05574b97eb60a64755ec9a51832d03bf85361e5 /Lib | |
parent | 2443766baec24f48944eebd44610116a3e2f46b1 (diff) | |
download | cpython-c47acc2bb1d0a3fb6dda14ced958d272fb2821a6.zip cpython-c47acc2bb1d0a3fb6dda14ced958d272fb2821a6.tar.gz cpython-c47acc2bb1d0a3fb6dda14ced958d272fb2821a6.tar.bz2 |
bpo-13312: Avoid int underflow in time year. (GH-8912)
Avoids an integer underflow in the time module's year handling code.
(cherry picked from commit 76be0fffff8b7dbe649ad4821144461800ffb0d0)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_time.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 0e0e906..b22546d 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -21,7 +21,7 @@ except ImportError: # Max year is only limited by the size of C int. SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4 TIME_MAXYEAR = (1 << 8 * SIZEOF_INT - 1) - 1 -TIME_MINYEAR = -TIME_MAXYEAR - 1 +TIME_MINYEAR = -TIME_MAXYEAR - 1 + 1900 SEC_TO_US = 10 ** 6 US_TO_NS = 10 ** 3 @@ -614,12 +614,11 @@ class _Test4dYear: self.assertEqual(self.yearstr(-123456), '-123456') self.assertEqual(self.yearstr(-123456789), str(-123456789)) self.assertEqual(self.yearstr(-1234567890), str(-1234567890)) - self.assertEqual(self.yearstr(TIME_MINYEAR + 1900), str(TIME_MINYEAR + 1900)) - # Issue #13312: it may return wrong value for year < TIME_MINYEAR + 1900 - # Skip the value test, but check that no error is raised - self.yearstr(TIME_MINYEAR) - # self.assertEqual(self.yearstr(TIME_MINYEAR), str(TIME_MINYEAR)) + self.assertEqual(self.yearstr(TIME_MINYEAR), str(TIME_MINYEAR)) + # Modules/timemodule.c checks for underflow self.assertRaises(OverflowError, self.yearstr, TIME_MINYEAR - 1) + with self.assertRaises(OverflowError): + self.yearstr(-TIME_MAXYEAR - 1) class TestAsctime4dyear(_TestAsctimeYear, _Test4dYear, unittest.TestCase): |