https://github.com/python/cpython/commit/185ac5adafb70a207b9d9ac7cb7808942813b832
commit: 185ac5adafb70a207b9d9ac7cb7808942813b832
branch: main
author: Bénédikt Tran <[email protected]>
committer: encukou <[email protected]>
date: 2025-02-18T14:48:21+01:00
summary:
gh-111178: fix UBSan failures in `Modules/_lzmamodule.c` (GH-129783)
fix UBSan failures for LZMA objects
suppress unused return values
files:
M Modules/_lzmamodule.c
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
index 97f3a8f03da9a8..0058e2eec2ef16 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -126,6 +126,9 @@ typedef struct {
PyThread_type_lock lock;
} Decompressor;
+#define Compressor_CAST(op) ((Compressor *)(op))
+#define Decompressor_CAST(op) ((Decompressor *)(op))
+
/* Helper functions. */
static int
@@ -857,14 +860,15 @@ Compressor_new(PyTypeObject *type, PyObject *args,
PyObject *kwargs)
}
static void
-Compressor_dealloc(Compressor *self)
+Compressor_dealloc(PyObject *op)
{
+ Compressor *self = Compressor_CAST(op);
lzma_end(&self->lzs);
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
PyTypeObject *tp = Py_TYPE(self);
- tp->tp_free((PyObject *)self);
+ tp->tp_free(self);
Py_DECREF(tp);
}
@@ -875,7 +879,7 @@ static PyMethodDef Compressor_methods[] = {
};
static int
-Compressor_traverse(Compressor *self, visitproc visit, void *arg)
+Compressor_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
@@ -1304,8 +1308,9 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int
format,
}
static void
-Decompressor_dealloc(Decompressor *self)
+Decompressor_dealloc(PyObject *op)
{
+ Decompressor *self = Decompressor_CAST(op);
if(self->input_buffer != NULL)
PyMem_Free(self->input_buffer);
@@ -1315,12 +1320,12 @@ Decompressor_dealloc(Decompressor *self)
PyThread_free_lock(self->lock);
}
PyTypeObject *tp = Py_TYPE(self);
- tp->tp_free((PyObject *)self);
+ tp->tp_free(self);
Py_DECREF(tp);
}
static int
-Decompressor_traverse(Decompressor *self, visitproc visit, void *arg)
+Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
@@ -1633,7 +1638,7 @@ lzma_clear(PyObject *module)
static void
lzma_free(void *module)
{
- lzma_clear((PyObject *)module);
+ (void)lzma_clear((PyObject *)module);
}
static PyModuleDef _lzmamodule = {
_______________________________________________
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]