Skip to content
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

gh-111178: fix UBSan failures in Modules/zlibmodule.c #128252

Merged
merged 1 commit into from
Jan 3, 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
14 changes: 9 additions & 5 deletions Modules/zlibmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
Loading