Issue #15989: Fix several occurrences of integer overflow
when result of PyInt_AsLong() or PyLong_AsLong() narrowed
to int without checks.
This is a backport of changesets 13e2e44db99d and 525407d89277.
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 7fe2454..6cd7d81 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -211,7 +211,7 @@
return -1;
}
- fd = PyLong_AsLong(nameobj);
+ fd = _PyLong_AsInt(nameobj);
if (fd < 0) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,