If pid_t has the same size as int, PyLong_AsPid is defined as PyLong_AsLong. if the size of int is less than the size of long, there are values out of the C int range but in the C long range. Calling PyLong_AsPid() with such argument will not raise an exception, but casting the result out of the C int range to pid_t has undefined behavior.
Most non-Windows 64-bit platforms are affected.
The simplest solution is to define PyLong_AsPid as PyLong_AsInt. It only applicable in 3.13, because PyLong_AsInt is new in 3.13. In older versions there is _PyLong_AsInt, but it is declared in Include/cpython/longobject.h, not in Include/longobject.h.
cc @vstinner, @pitrou
Linked PRs
If
pid_thas the same size asint,PyLong_AsPidis defined asPyLong_AsLong. if the size ofintis less than the size oflong, there are values out of the Cintrange but in the Clongrange. CallingPyLong_AsPid()with such argument will not raise an exception, but casting the result out of the Cintrange topid_thas undefined behavior.Most non-Windows 64-bit platforms are affected.
The simplest solution is to define
PyLong_AsPidasPyLong_AsInt. It only applicable in 3.13, becausePyLong_AsIntis new in 3.13. In older versions there is_PyLong_AsInt, but it is declared inInclude/cpython/longobject.h, not inInclude/longobject.h.cc @vstinner, @pitrou
Linked PRs