Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method#3227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
6338b6a6c0f6e408969fca7b4e5a8299f61File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,7 +18,7 @@ | ||
| from array import array | ||
| from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod, mul | ||
| from test import support | ||
| @@ -866,6 +866,15 @@ def test_divmod(self): | ||
| self.assertRaises(TypeError, divmod, t, 10) | ||
| def test_issue31293(self): | ||
| # The interpreter shouldn't crash in case a timedelta is divided or | ||
| # multiplied by a float with a bad as_integer_ratio() method. | ||
| class BadFloat(float): | ||
| def as_integer_ratio(self): | ||
| return (1 << 1000) - 1 | ||
| self.assertRaises(TypeError, truediv, timedelta(), BadFloat()) | ||
| ||
| self.assertRaises(TypeError, mul, timedelta(), BadFloat()) | ||
| ############################################################################# | ||
| # date tests | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix crashes in true division and multiplication of a timedelta object by a | ||
| float with a bad as_integer_ratio() method. Patch by Oren Milman. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1664,6 +1664,12 @@ multiply_float_timedelta(PyObject *floatobj, PyDateTime_Delta *delta) | ||
| ratio = _PyObject_CallMethodId(floatobj, &PyId_as_integer_ratio, NULL); | ||
| if (ratio == NULL) | ||
| goto error; | ||
| if (!PyTuple_Check(ratio)) { | ||
| ||
| PyErr_SetString(PyExc_TypeError, | ||
| "Can't multiply timedelta object by float with " | ||
| ||
| "bad as_integer_ratio() method"); | ||
| goto error; | ||
| } | ||
| temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 0)); | ||
| Py_DECREF(pyus_in); | ||
| pyus_in = NULL; | ||
| @@ -1762,6 +1768,12 @@ truedivide_timedelta_float(PyDateTime_Delta *delta, PyObject *f) | ||
| ratio = _PyObject_CallMethodId(f, &PyId_as_integer_ratio, NULL); | ||
| if (ratio == NULL) | ||
| goto error; | ||
| if (!PyTuple_Check(ratio)) { | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "Can't divide timedelta object by float with " | ||
| "bad as_integer_ratio() method"); | ||
| goto error; | ||
| } | ||
| temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 1)); | ||
| Py_DECREF(pyus_in); | ||
| pyus_in = NULL; | ||