From: Victor Stinner Date: Thu, 1 Dec 2022 13:07:58 +0000 (+0100) Subject: gh-99845: _PyObject_DictPointer(): fix dictoffset cast (#99922) X-Git-Tag: v3.11.1~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9707bf228e008485a3fbb63aa7ee28cf88014f91;p=thirdparty%2FPython%2Fcpython.git gh-99845: _PyObject_DictPointer(): fix dictoffset cast (#99922) Cast size_t to Py_ssize_t, rather than casting it to long. On 64-bit Windows, long is 32-bit whereas Py_ssize_t is 64-bit. --- diff --git a/Objects/object.c b/Objects/object.c index 6a22f27de0b1..c4f2786c50a0 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1076,8 +1076,9 @@ _PyObject_DictPointer(PyObject *obj) tsize = -tsize; } size_t size = _PyObject_VAR_SIZE(tp, tsize); + assert(size <= (size_t)PY_SSIZE_T_MAX); + dictoffset += (Py_ssize_t)size; - dictoffset += (long)size; _PyObject_ASSERT(obj, dictoffset > 0); _PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0); }