diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-11-15 11:22:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-11-15 11:22:27 (GMT) |
commit | 42826566f5da776c729f65f6b6ab425c738a8bfa (patch) | |
tree | 118bc5fb0e2f13aceca7579544d80c2dd8fe9a77 /Python | |
parent | 7aaa67eb0d53e4347d2022279d5f55be3da8afa2 (diff) | |
parent | 030e92d1a51c2caef0c23a74e65f0aaff002158f (diff) | |
download | cpython-42826566f5da776c729f65f6b6ab425c738a8bfa.zip cpython-42826566f5da776c729f65f6b6ab425c738a8bfa.tar.gz cpython-42826566f5da776c729f65f6b6ab425c738a8bfa.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.c | 15 |
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 * |