summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-15 11:21:37 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-15 11:21:37 (GMT)
commit030e92d1a51c2caef0c23a74e65f0aaff002158f (patch)
tree3c2c3398992dedd8137917ea47af73ca34f531b8 /Python
parented7301031917a5f63ca2e9a7cccb6b18113ca27c (diff)
downloadcpython-030e92d1a51c2caef0c23a74e65f0aaff002158f.zip
cpython-030e92d1a51c2caef0c23a74e65f0aaff002158f.tar.gz
cpython-030e92d1a51c2caef0c23a74e65f0aaff002158f.tar.bz2
Issue #22193: Fixed integer overflow error in sys.getsizeof().
Fixed an error in _PySys_GetSizeOf declaration.
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 39fe53f..106fc84 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -868,7 +868,7 @@ _PySys_GetSizeOf(PyObject *o)
{
PyObject *res = NULL;
PyObject *method;
- size_t size;
+ Py_ssize_t size;
/* Make sure the type is initialized. float gets initialized late */
if (PyType_Ready(Py_TYPE(o)) < 0)
@@ -889,15 +889,20 @@ _PySys_GetSizeOf(PyObject *o)
if (res == NULL)
return (size_t)-1;
- size = PyLong_AsSize_t(res);
+ size = PyLong_AsSsize_t(res);
Py_DECREF(res);
- if (size == (size_t)-1 && PyErr_Occurred())
+ if (size == -1 && PyErr_Occurred())
+ return (size_t)-1;
+
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "__sizeof__() should return >= 0");
return (size_t)-1;
+ }
/* add gc_head size */
if (PyObject_IS_GC(o))
- size += sizeof(PyGC_Head);
- return size;
+ return ((size_t)size) + sizeof(PyGC_Head);
+ return (size_t)size;
}
static PyObject *