summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-10-23 15:20:13 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-23 15:20:13 (GMT)
commit6e45d7b90accbbdfef353c41ab0a78a3e4742803 (patch)
tree12d365a7f7ecf144b54677b11fb72e6e0e3f0b90 /Lib/test
parentaaf6a3dbbdb9754f98d480b468adfcae0f66e3a2 (diff)
downloadcpython-6e45d7b90accbbdfef353c41ab0a78a3e4742803.zip
cpython-6e45d7b90accbbdfef353c41ab0a78a3e4742803.tar.gz
cpython-6e45d7b90accbbdfef353c41ab0a78a3e4742803.tar.bz2
bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (GH-3947) (#4086)
Bad remainder in divmod() in intermediate calculations caused an assertion failure. (cherry picked from commit 4ffd4653a7ec9c97775472276cf5e159e2366bb2)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/datetimetester.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 77df1b3..c00e38c 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -866,6 +866,26 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
with self.assertRaises(ValueError):
timedelta() * get_bad_float(bad_ratio)
+ def test_issue31752(self):
+ # The interpreter shouldn't crash because divmod() returns negative
+ # remainder.
+ class BadInt(int):
+ def __mul__(self, other):
+ return Prod()
+
+ class Prod:
+ def __radd__(self, other):
+ return Sum()
+
+ class Sum(int):
+ def __divmod__(self, other):
+ # negative remainder
+ return (0, -1)
+
+ timedelta(microseconds=BadInt(1))
+ timedelta(hours=BadInt(1))
+ timedelta(weeks=BadInt(1))
+
#############################################################################
# date tests