]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111178: fix UBSan failures in `Modules/zlibmodule.c` (GH-128252)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Fri, 3 Jan 2025 14:36:41 +0000 (15:36 +0100)
committerGitHub <noreply@github.com>
Fri, 3 Jan 2025 14:36:41 +0000 (15:36 +0100)
Modules/zlibmodule.c

index 78dcce73cdaade5d3a23743e608e5d922c1522ea..b90665ae7ef64a2014fe760e7a61d25893e33359 100644 (file)
@@ -221,6 +221,8 @@ typedef struct
     PyThread_type_lock lock;
 } compobject;
 
+#define _compobject_CAST(op)    ((compobject *)op)
+
 static void
 zlib_error(zlibstate *state, z_stream zst, int err, const char *msg)
 {
@@ -706,7 +708,7 @@ zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict)
 static void
 Dealloc(compobject *self)
 {
-    PyObject *type = (PyObject *)Py_TYPE(self);
+    PyTypeObject *type = Py_TYPE(self);
     PyThread_free_lock(self->lock);
     Py_XDECREF(self->unused_data);
     Py_XDECREF(self->unconsumed_tail);
@@ -716,18 +718,20 @@ Dealloc(compobject *self)
 }
 
 static void
-Comp_dealloc(compobject *self)
+Comp_dealloc(PyObject *op)
 {
+    compobject *self = _compobject_CAST(op);
     if (self->is_initialised)
-        deflateEnd(&self->zst);
+        (void)deflateEnd(&self->zst);
     Dealloc(self);
 }
 
 static void
-Decomp_dealloc(compobject *self)
+Decomp_dealloc(PyObject *op)
 {
+    compobject *self = _compobject_CAST(op);
     if (self->is_initialised)
-        inflateEnd(&self->zst);
+        (void)inflateEnd(&self->zst);
     Dealloc(self);
 }