Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97953:edba5d677359
Date: 2019-11-04 18:33 +0000
http://bitbucket.org/pypy/pypy/changeset/edba5d677359/
Log: Fix range of allowed years to match CPython (see bpo-13312)
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -10,7 +10,8 @@
str_decode_locale_surrogateescape, unicode_encode_locale_surrogateescape)
from rpython.rtyper.lltypesystem import lltype
from rpython.rlib.rarithmetic import (
- intmask, r_ulonglong, r_longfloat, widen, ovfcheck, ovfcheck_float_to_int)
+ intmask, r_ulonglong, r_longfloat, widen, ovfcheck, ovfcheck_float_to_int,
+ INT_MIN)
from rpython.rlib.rtime import (GETTIMEOFDAY_NO_TZ, TIMEVAL,
HAVE_GETTIMEOFDAY, HAVE_FTIME)
from rpython.rlib import rposix, rtime
@@ -593,6 +594,8 @@
len(tup_w))
y = space.c_int_w(tup_w[0])
+ if y < INT_MIN + 1900:
+ raise oefmt(space.w_OverflowError, "year out of range")
tm_mon = space.c_int_w(tup_w[1])
if tm_mon == 0:
tm_mon = 1
diff --git a/pypy/module/time/test/test_time.py
b/pypy/module/time/test/test_time.py
--- a/pypy/module/time/test/test_time.py
+++ b/pypy/module/time/test/test_time.py
@@ -153,6 +153,17 @@
else:
assert time.ctime(res) == 'Sat Jan 1 00:00:00 2000'
+ def test_mktime_overflow(self):
+ import time
+ MAX_YEAR = (1 << 31) - 1
+ MIN_YEAR = -(1 << 31) + 1900
+ time.mktime((MAX_YEAR,) + (0,) * 8) # doesn't raise
+ with raises(OverflowError):
+ time.mktime((MAX_YEAR + 1,) + (0,) * 8)
+ time.mktime((MIN_YEAR,) + (0,) * 8) # doesn't raise
+ with raises(OverflowError):
+ time.mktime((MIN_YEAR - 1,) + (0,) * 8)
+
def test_asctime(self):
import time
time.asctime()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit