Commit cf74c199 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #24613: Calling array.fromstring() with self is no longer allowed

to prevent the use-after-free error.  Patch by John Leitch.
parent 7f18ac4a
...@@ -247,6 +247,7 @@ class BaseTest(unittest.TestCase): ...@@ -247,6 +247,7 @@ class BaseTest(unittest.TestCase):
self.assertRaises(TypeError, a.tostring, 42) self.assertRaises(TypeError, a.tostring, 42)
self.assertRaises(TypeError, b.fromstring) self.assertRaises(TypeError, b.fromstring)
self.assertRaises(TypeError, b.fromstring, 42) self.assertRaises(TypeError, b.fromstring, 42)
self.assertRaises(ValueError, a.fromstring, a)
b.fromstring(a.tostring()) b.fromstring(a.tostring())
self.assertEqual(a, b) self.assertEqual(a, b)
if a.itemsize>1: if a.itemsize>1:
......
...@@ -34,6 +34,9 @@ Core and Builtins ...@@ -34,6 +34,9 @@ Core and Builtins
Library Library
------- -------
- Issue #24613: Calling array.fromstring() with self is no longer allowed
to prevent the use-after-free error. Patch by John Leitch.
- Issue #24708: Fix possible integer overflow in strop.replace(). - Issue #24708: Fix possible integer overflow in strop.replace().
- Issue #24620: Random.setstate() now validates the value of state last element. - Issue #24620: Random.setstate() now validates the value of state last element.
......
...@@ -1380,6 +1380,11 @@ array_fromstring(arrayobject *self, PyObject *args) ...@@ -1380,6 +1380,11 @@ array_fromstring(arrayobject *self, PyObject *args)
int itemsize = self->ob_descr->itemsize; int itemsize = self->ob_descr->itemsize;
if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n)) if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n))
return NULL; return NULL;
if (str == self->ob_item) {
PyErr_SetString(PyExc_ValueError,
"array.fromstring(x): x cannot be self");
return NULL;
}
if (n % itemsize != 0) { if (n % itemsize != 0) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"string length not a multiple of item size"); "string length not a multiple of item size");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment