8000 gh-111178: fix UBSan failures in `Modules/_pickle.c` by picnixz · Pull Request #129787 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/_pickle.c #129787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 20, 2025
Prev Previous commit
Next Next commit
fix UBSan failures for UnpicklerMemoProxyObject
  • Loading branch information
picnixz committed Jan 25, 2025
commit e3bcf30bbcfe91387fa4ab46c41d82b2c25f663b
13 changes: 8 additions & 5 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ typedef struct {
#define _PicklerObject_CAST(op) ((PicklerObject *)(op))
#define _UnpicklerObject_CAST(op) ((UnpicklerObject *)(op))
#define _PicklerMemoProxyObject_CAST(op) ((PicklerMemoProxyObject *)(op))
#define _UnpicklerMemoProxyObject_CAST(op) ((UnpicklerMemoProxyObject *)(op))

/* Forward declarations */
static int save(PickleState *state, PicklerObject *, PyObject *, int);
Expand Down Expand Up @@ -7473,27 +7474,29 @@ static PyMethodDef unpicklerproxy_methods[] = {
};

static void
UnpicklerMemoProxy_dealloc(UnpicklerMemoProxyObject *self)
UnpicklerMemoProxy_dealloc(PyObject *op)
{
UnpicklerMemoProxyObject *self = _UnpicklerMemoProxyObject_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
Py_CLEAR(self->unpickler);
tp->tp_free((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
}

static int
UnpicklerMemoProxy_traverse(UnpicklerMemoProxyObject *self,
visitproc visit, void *arg)
UnpicklerMemoProxy_traverse(PyObject *op, visitproc visit, void *arg)
{
UnpicklerMemoProxyObject *self = _UnpicklerMemoProxyObject_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->unpickler);
return 0;
}

static int
UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self)
UnpicklerMemoProxy_clear(PyObject *op)
{
UnpicklerMemoProxyObject *self = _UnpicklerMemoProxyObject_CAST(op);
Py_CLEAR(self->unpickler);
return 0;
}
Expand Down
0