https://github.com/python/cpython/commit/aa444bc4afadbd9eba2fec79eb685d4fc1ca3d99
commit: aa444bc4afadbd9eba2fec79eb685d4fc1ca3d99
branch: main
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2025-03-24T10:52:52+01:00
summary:
gh-111178: fix UBSan failures for `PyBufferWrapper` (#131616)
files:
M Objects/typeobject.c
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 25153182f29487..fc4950ef30aec6 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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;
@@ -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);
@@ -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
@@ -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,
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]