gh-111178: fix UBSan failures in Modules/zlibmodule.c (GH-128252)

This commit is contained in:
Bénédikt Tran 2025-01-03 15:36:41 +01:00 committed by GitHub
parent 5643032053
commit 1c9b020479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -221,6 +221,8 @@ typedef struct
PyThread_type_lock lock; PyThread_type_lock lock;
} compobject; } compobject;
#define _compobject_CAST(op) ((compobject *)op)
static void static void
zlib_error(zlibstate *state, z_stream zst, int err, const char *msg) 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 static void
Dealloc(compobject *self) Dealloc(compobject *self)
{ {
PyObject *type = (PyObject *)Py_TYPE(self); PyTypeObject *type = Py_TYPE(self);
PyThread_free_lock(self->lock); PyThread_free_lock(self->lock);
Py_XDECREF(self->unused_data); Py_XDECREF(self->unused_data);
Py_XDECREF(self->unconsumed_tail); Py_XDECREF(self->unconsumed_tail);
@ -716,18 +718,20 @@ Dealloc(compobject *self)
} }
static void static void
Comp_dealloc(compobject *self) Comp_dealloc(PyObject *op)
{ {
compobject *self = _compobject_CAST(op);
if (self->is_initialised) if (self->is_initialised)
deflateEnd(&self->zst); (void)deflateEnd(&self->zst);
Dealloc(self); Dealloc(self);
} }
static void static void
Decomp_dealloc(compobject *self) Decomp_dealloc(PyObject *op)
{ {
compobject *self = _compobject_CAST(op);
if (self->is_initialised) if (self->is_initialised)
inflateEnd(&self->zst); (void)inflateEnd(&self->zst);
Dealloc(self); Dealloc(self);
} }