From 4cfa774c3622305dc867392df2d691faa866ce7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Tue, 7 Mar 2023 11:25:54 +0100 Subject: [PATCH 1/2] gh-102494: fix MemoryError when using selectors on Solaris --- Modules/selectmodule.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index df4043de08dacc..38f69f29f4cc45 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1095,7 +1095,7 @@ newDevPollObject(PyObject *module) struct rlimit limit; /* - ** If we try to process more that getrlimit() + ** If we try to process more than getrlimit() ** fds, the kernel will give an error, so ** we set the limit here. It is a dynamic ** value, because we can change rlimit() anytime. @@ -1106,6 +1106,15 @@ newDevPollObject(PyObject *module) return NULL; } + /* + ** If the limit is too high (or RLIM_INFINITY), we might allocate huge + ** amounts of memory (or even fail to allocate). Because of that, we limit + ** the number of allocated structs to 2^18 (which is ~4MB of memory). + */ + if (limit.rlim_cur > (rlim_t)262144) { + limit.rlim_cur = (rlim_t)262144; + } + fd_devpoll = _Py_open("/dev/poll", O_RDWR); if (fd_devpoll == -1) return NULL; From 5a1e5f987a321579fbc6d92fcf3bc7ff63e22ddd Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 7 Mar 2023 10:41:41 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-03-07-10-41-37.gh-issue-102494.-fBwpb.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-03-07-10-41-37.gh-issue-102494.-fBwpb.rst diff --git a/Misc/NEWS.d/next/Library/2023-03-07-10-41-37.gh-issue-102494.-fBwpb.rst b/Misc/NEWS.d/next/Library/2023-03-07-10-41-37.gh-issue-102494.-fBwpb.rst new file mode 100644 index 00000000000000..7439dc8fbea2da --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-03-07-10-41-37.gh-issue-102494.-fBwpb.rst @@ -0,0 +1 @@ +The devpoll object now has an upper limit on number of registered file descriptors of 2^18 to prevent memory exhaustion at the time of instantiation.