Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,14 @@ class F(float, H):
value = F('nan')
self.assertEqual(hash(value), object.__hash__(value))

def test_issue_gh143006(self):
class EvilInt(int):
def __neg__(self):
return

i = -1<<50
self.assertRaises(TypeError, operator.ge, float(i), EvilInt(i))


@unittest.skipUnless(hasattr(float, "__getformat__"), "requires __getformat__")
class FormatFunctionsTestCase(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add missing type check for rich comparison methods of the :class:`float` to
avoid possible crash with integer operand, having broken implementation of
the :meth:`object.__neg__` method.
6 changes: 6 additions & 0 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ float_richcompare(PyObject *v, PyObject *w, int op)
ww = PyNumber_Negative(w);
if (ww == NULL)
goto Error;
else if (!PyLong_Check(ww)) {
PyErr_SetString(PyExc_TypeError,
"unexpected type from negation "
"of integer operand");
Comment thread
skirpichev marked this conversation as resolved.
Outdated
goto Error;
}
}
else
Py_INCREF(ww);
Expand Down
Loading