]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99845: _PyObject_DictPointer(): fix dictoffset cast (GH-99922)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 1 Dec 2022 13:32:15 +0000 (05:32 -0800)
committerGitHub <noreply@github.com>
Thu, 1 Dec 2022 13:32:15 +0000 (05:32 -0800)
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.
(cherry picked from commit 9707bf228e008485a3fbb63aa7ee28cf88014f91)

Co-authored-by: Victor Stinner <vstinner@python.org>
Objects/object.c

index 6d80d6df74103138fb06bccc5cf102eb58814447..0bef2e9dfb5e359f6aed9592ef29fc267f56a70b 100644 (file)
@@ -1091,8 +1091,9 @@ _PyObject_GetDictPtr(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);
     }