8000 gh-111178: fix UBSan failures for `PyBufferWrapper` by picnixz · Pull Request #131616 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures for PyBufferWrapper #131616

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 2 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10372,9 +10372,12 @@ typedef struct _PyBufferWrapper {
PyObject *obj;
} PyBufferWrapper;

#define PyBufferWrapper_CAST(op) ((PyBufferWrapper *)(op))

static int
bufferwrapper_traverse(PyBufferWrapper *self, visitproc visit, void *arg)
bufferwrapper_traverse(PyObject *op, visitproc visit, void *arg)
{
PyBufferWrapper *self = PyBufferWrapper_CAST(op);
Py_VISIT(self->mv);
Py_VISIT(self->obj);
return 0;
Expand All @@ -10383,7 +10386,7 @@ bufferwrapper_traverse(PyBufferWrapper *self, visitproc visit, void *arg)
static void
bufferwrapper_dealloc(PyObject *self)
{
PyBufferWrapper *bw = (PyBufferWrapper *)self;
PyBufferWrapper *bw = PyBufferWrapper_CAST(self);

_PyObject_GC_UNTRACK(self);
Py_XDECREF(bw->mv);
Expand All @@ -10394,7 +10397,7 @@ bufferwrapper_dealloc(PyObject *self)
static void
bufferwrapper_releasebuf(PyObject *self, Py_buffer *view)
{
PyBufferWrapper *bw = (PyBufferWrapper *)self;
PyBufferWrapper *bw = PyBufferWrapper_CAST(self);

if (bw->mv == NULL || bw->obj == NULL) {
// Already released
Expand Down Expand Up @@ -10429,7 +10432,7 @@ PyTypeObject _PyBufferWrapper_Type = {
.tp_basicsize = sizeof(PyBufferWrapper),
.tp_alloc = PyType_GenericAlloc,
.tp_free = PyObject_GC_Del,
.tp_traverse = (traverseproc)bufferwrapper_traverse,
.tp_traverse = bufferwrapper_traverse,
.tp_dealloc = bufferwrapper_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.tp_as_buffer = &bufferwrapper_as_buffer,
Expand Down
Loading
0