https://github.com/python/cpython/commit/f28f9304bf6d79c7ce2274e9f929fabde26d7afb
commit: f28f9304bf6d79c7ce2274e9f929fabde26d7afb
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2025-05-30T12:50:42+02:00
summary:

[3.14] gh-134885: zstd: Use Py_XSETREF (GH-134886) (GH-134922)

(cherry picked from commit 45c6c48afc13f9897010e32171a3e02d0624258c)

Co-authored-by: Jelle Zijlstra <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst
M Modules/_zstd/_zstdmodule.c

diff --git 
a/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst 
b/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst
new file mode 100644
index 00000000000000..4b05d42c109d06
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-05-29-06-53-40.gh-issue-134885.-_L22o.rst
@@ -0,0 +1,2 @@
+Fix possible crash in the :mod:`compression.zstd` module related to setting
+parameter types. Patch by Jelle Zijlstra.
diff --git a/Modules/_zstd/_zstdmodule.c b/Modules/_zstd/_zstdmodule.c
index 5ad697d2b83dd6..986b3579479f0f 100644
--- a/Modules/_zstd/_zstdmodule.c
+++ b/Modules/_zstd/_zstdmodule.c
@@ -514,13 +514,10 @@ _zstd_set_parameter_types_impl(PyObject *module, PyObject 
*c_parameter_type,
         return NULL;
     }
 
-    Py_XDECREF(mod_state->CParameter_type);
-    Py_INCREF(c_parameter_type);
-    mod_state->CParameter_type = (PyTypeObject*)c_parameter_type;
-
-    Py_XDECREF(mod_state->DParameter_type);
-    Py_INCREF(d_parameter_type);
-    mod_state->DParameter_type = (PyTypeObject*)d_parameter_type;
+    Py_XSETREF(
+        mod_state->CParameter_type, 
(PyTypeObject*)Py_NewRef(c_parameter_type));
+    Py_XSETREF(
+        mod_state->DParameter_type, 
(PyTypeObject*)Py_NewRef(d_parameter_type));
 
     Py_RETURN_NONE;
 }

_______________________________________________
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]

Reply via email to