From 3fa024dec32e2ff86baf3dd7e14a0b314855327c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 25 Apr 2025 13:02:57 +0200 Subject: [PATCH] gh-132909: handle overflow for `'K'` format in `do_mkvalue` (#132911) --- Doc/c-api/arg.rst | 2 ++ .../next/C_API/2025-04-25-11-39-24.gh-issue-132909.JC3n_l.rst | 2 ++ Python/modsupport.c | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-04-25-11-39-24.gh-issue-132909.JC3n_l.rst diff --git a/Doc/c-api/arg.rst b/Doc/c-api/arg.rst index 81b093a35109..d68dc0885681 100644 --- a/Doc/c-api/arg.rst +++ b/Doc/c-api/arg.rst @@ -669,6 +669,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 000000000000..81a37d0595e2 --- /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 ` format +in :c:func:`Py_BuildValue`. Patch by Bénédikt Tran. diff --git a/Python/modsupport.c b/Python/modsupport.c index 501231affe8c..2caf595949d5 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -321,7 +321,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': {