Skip to content

Commit

Permalink
pythongh-101408: PyObject_GC_Resize should calculate preheader size.
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Feb 10, 2023
1 parent 34c50ce commit 0ca174c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
@@ -0,0 +1,2 @@
:c:func:`PyObject_GC_Resize` should calculate preheader size if needed.
Patch by Dong-hee Na.
5 changes: 3 additions & 2 deletions Modules/gcmodule.c
Expand Up @@ -2348,13 +2348,14 @@ PyVarObject *
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
{
const size_t basicsize = _PyObject_VAR_SIZE(Py_TYPE(op), nitems);
const size_t presize = _PyType_PreHeaderSize(((PyObject *)op)->ob_type);
_PyObject_ASSERT((PyObject *)op, !_PyObject_GC_IS_TRACKED(op));
if (basicsize > (size_t)PY_SSIZE_T_MAX - sizeof(PyGC_Head)) {
if (basicsize > (size_t)PY_SSIZE_T_MAX - presize) {
return (PyVarObject *)PyErr_NoMemory();
}

PyGC_Head *g = AS_GC(op);
g = (PyGC_Head *)PyObject_Realloc(g, sizeof(PyGC_Head) + basicsize);
g = (PyGC_Head *)PyObject_Realloc(g, presize + basicsize);
if (g == NULL)
return (PyVarObject *)PyErr_NoMemory();
op = (PyVarObject *) FROM_GC(g);
Expand Down

0 comments on commit 0ca174c

Please sign in to comment.