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 PicklerMemoProxyObject
  • Loading branch information
picnixz committed Jan 25, 2025
commit 0b1d7266f62506fd8ab3ae9b5d4f9dd2146e4c6d
13 changes: 8 additions & 5 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ typedef struct {

#define _PicklerObject_CAST(op) ((PicklerObject *)(op))
#define _UnpicklerObject_CAST(op) ((UnpicklerObject *)(op))
#define _PicklerMemoProxyObject_CAST(op) ((PicklerMemoProxyObject *)(op))

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

static void
PicklerMemoProxy_dealloc(PicklerMemoProxyObject *self)
PicklerMemoProxy_dealloc(PyObject *op)
{
PicklerMemoProxyObject *self = _PicklerMemoProxyObject_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
Py_CLEAR(self->pickler);
tp->tp_free((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
}

static int
PicklerMemoProxy_traverse(PicklerMemoProxyObject *self,
visitproc visit, void *arg)
PicklerMemoProxy_traverse(PyObject *op, visitproc visit, void *arg)
{
PicklerMemoProxyObject *self = _PicklerMemoProxyObject_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->pickler);
return 0;
}

static int
PicklerMemoProxy_clear(PicklerMemoProxyObject *self)
PicklerMemoProxy_clear(PyObject *op)
{
PicklerM 492E emoProxyObject *self = _PicklerMemoProxyObject_CAST(op);
Py_CLEAR(self->pickler);
return 0;
}
Expand Down
0