diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-23 17:12:28 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-23 17:12:28 +0300 |
| commit | 4ffd4653a7ec9c97775472276cf5e159e2366bb2 (patch) | |
| tree | dde6087a2aa8c149de6cc7894a5e809ba4f2b32a /Lib/test/datetimetester.py | |
| parent | 7fed7bd8bb628f0f09c6011871a4ce68afb41b18 (diff) | |
| download | cpython-git-4ffd4653a7ec9c97775472276cf5e159e2366bb2.tar.gz | |
bpo-31752: Fix possible crash in timedelta constructor called with custom integers. (#3947)
Bad remainder in divmod() in intermediate calculations caused an assertion failure.
Diffstat (limited to 'Lib/test/datetimetester.py')
| -rw-r--r-- | Lib/test/datetimetester.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index a042efd878..4edfb42d35 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -886,6 +886,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 |
