https://github.com/python/cpython/commit/7ebfc6ec5e83364f9c219821a308db6aad5ad438
commit: 7ebfc6ec5e83364f9c219821a308db6aad5ad438
branch: 3.13
author: Bénédikt Tran <10796600+picn...@users.noreply.github.com>
committer: picnixz <10796600+picn...@users.noreply.github.com>
date: 2025-04-25T12:44:53Z
summary:

[3.13] gh-132909: handle overflow for `'K'` format in `do_mkvalue` (GH-132911) 
(#132932)

(cherry picked from commit 3fa024dec32e2ff86baf3dd7e14a0b314855327c)

files:
A Misc/NEWS.d/next/C API/2025-04-25-11-39-24.gh-issue-132909.JC3n_l.rst
M Doc/c-api/arg.rst
M Python/modsupport.c

diff --git a/Doc/c-api/arg.rst b/Doc/c-api/arg.rst
index 15402a4c48f569..9420ae050814c5 100644
--- a/Doc/c-api/arg.rst
+++ b/Doc/c-api/arg.rst
@@ -639,6 +639,8 @@ Building values
    ``L`` (:class:`int`) [long long]
       Convert a C :c:expr:`long long` to a Python integer object.
 
+   .. _capi-py-buildvalue-format-K:
+
    ``K`` (:class:`int`) [unsigned long long]
       Convert a C :c:expr:`unsigned long long` to a Python integer object.
 
diff --git a/Misc/NEWS.d/next/C 
API/2025-04-25-11-39-24.gh-issue-132909.JC3n_l.rst b/Misc/NEWS.d/next/C 
API/2025-04-25-11-39-24.gh-issue-132909.JC3n_l.rst
new file mode 100644
index 00000000000000..81a37d0595e2e0
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2025-04-25-11-39-24.gh-issue-132909.JC3n_l.rst     
@@ -0,0 +1,2 @@
+Fix an overflow when handling the :ref:`K <capi-py-buildvalue-format-K>` format
+in :c:func:`Py_BuildValue`. Patch by Bénédikt Tran.
diff --git a/Python/modsupport.c b/Python/modsupport.c
index e9abf304e6502c..cf4ab39f380358 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -320,7 +320,8 @@ do_mkvalue(const char **p_format, va_list *p_va)
             return PyLong_FromLongLong((long long)va_arg(*p_va, long long));
 
         case 'K':
-            return PyLong_FromUnsignedLongLong((long long)va_arg(*p_va, 
unsigned long long));
+            return PyLong_FromUnsignedLongLong(
+                va_arg(*p_va, unsigned long long));
 
         case 'u':
         {

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to