From e9c2a357fba72e46e965ecaa54e78be69c6c5d6b Mon Sep 17 00:00:00 2001 From: asas1asas200 Date: Fri, 5 Sep 2025 14:48:05 +0800 Subject: [PATCH 1/4] gh-138516: fix typo in OrderedDict exception msg (#138517) --- Objects/odictobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 59a956c6adfa99..bcdf94c6c64faa 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1519,7 +1519,7 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds) if (len == -1) return -1; if (len > 1) { - const char *msg = "expected at most 1 arguments, got %zd"; + const char *msg = "expected at most 1 argument, got %zd"; PyErr_Format(PyExc_TypeError, msg, len); return -1; } From f19f1d8563fb3abbb673812f16e2be5f10af42e4 Mon Sep 17 00:00:00 2001 From: Ric <11750904+ricsatjr@users.noreply.github.com> Date: Fri, 5 Sep 2025 15:16:04 +0800 Subject: [PATCH 2/4] gh-107194: Improved language of list.index in tutorial (gh-138518) --- Doc/tutorial/datastructures.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index cbe780e075baf5..ba47d7ab446bc9 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -62,7 +62,7 @@ objects: .. method:: list.index(x[, start[, end]]) :noindex: - Return zero-based index in the list of the first item whose value is equal to *x*. + Return zero-based index of the first occurrence of *x* in the list. Raises a :exc:`ValueError` if there is no such item. The optional arguments *start* and *end* are interpreted as in the slice From d1d84098f6ac408ef36f1a85a4bc80d857d0f4ff Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Fri, 5 Sep 2025 16:34:18 +0800 Subject: [PATCH 3/4] gh-138515: Include email module in Emscripten build (gh-138520) --- .../next/Library/2025-09-05-07-50-18.gh-issue-138515.E3M-pu.rst | 1 + Tools/wasm/emscripten/wasm_assets.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-09-05-07-50-18.gh-issue-138515.E3M-pu.rst diff --git a/Misc/NEWS.d/next/Library/2025-09-05-07-50-18.gh-issue-138515.E3M-pu.rst b/Misc/NEWS.d/next/Library/2025-09-05-07-50-18.gh-issue-138515.E3M-pu.rst new file mode 100644 index 00000000000000..12712b82888ef0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-05-07-50-18.gh-issue-138515.E3M-pu.rst @@ -0,0 +1 @@ +:mod:`email` is added to Emscripten build. diff --git a/Tools/wasm/emscripten/wasm_assets.py b/Tools/wasm/emscripten/wasm_assets.py index b08e7ce1114a4a..78da913ff6059b 100755 --- a/Tools/wasm/emscripten/wasm_assets.py +++ b/Tools/wasm/emscripten/wasm_assets.py @@ -58,7 +58,6 @@ # socket.create_connection() raises an exception: # "BlockingIOError: [Errno 26] Operation in progress". OMIT_NETWORKING_FILES = ( - "email/", "ftplib.py", "http/", "imaplib.py", From ed53c63769ba8a372c321fe6ef4916444f6f4db8 Mon Sep 17 00:00:00 2001 From: Christoph Walcher Date: Fri, 5 Sep 2025 11:16:55 +0200 Subject: [PATCH 4/4] gh-138401: Check arg count>=0 in os.sendfile() (#138403) Co-authored-by: Victor Stinner Co-authored-by: Kumar Aditya --- Lib/test/test_os.py | 5 +++++ ...5-09-02-22-17-55.gh-issue-138401.uTRvue.rst | 2 ++ Modules/clinic/posixmodule.c.h | 12 +++++++++++- Modules/posixmodule.c | 18 ++++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-09-02-22-17-55.gh-issue-138401.uTRvue.rst diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 9827a7f12ea21d..b476b431ad6f96 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3957,6 +3957,11 @@ async def test_invalid_offset(self): await self.async_sendfile(self.sockno, self.fileno, -1, 4096) self.assertEqual(cm.exception.errno, errno.EINVAL) + async def test_invalid_count(self): + with self.assertRaises(ValueError, msg="count cannot be negative"): + await self.sendfile_wrapper(self.sockno, self.fileno, offset=0, + count=-1) + async def test_keywords(self): # Keyword arguments should be supported await self.async_sendfile(out_fd=self.sockno, in_fd=self.fileno, diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-09-02-22-17-55.gh-issue-138401.uTRvue.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-09-02-22-17-55.gh-issue-138401.uTRvue.rst new file mode 100644 index 00000000000000..90496c05c56e13 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-09-02-22-17-55.gh-issue-138401.uTRvue.rst @@ -0,0 +1,2 @@ +Add missing validation of argument ``count`` in :func:`os.sendfile` to be +non-negative. diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 455c938afc75f0..45e7c0d6451c15 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -8100,6 +8100,11 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject goto exit; } count = ival; + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; + } } if (!noptargs) { goto skip_optional_pos; @@ -8206,6 +8211,11 @@ os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject goto exit; } count = ival; + if (count < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + goto exit; + } } return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); @@ -13434,4 +13444,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=77c20b53c34ccae4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=92662828d49f5d88 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index f7e721e52e11b0..53b21e99376485 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -11874,7 +11874,7 @@ os.sendfile out_fd: int in_fd: int offset: Py_off_t - count: Py_ssize_t + count: Py_ssize_t(allow_negative=False) headers: object(c_default="NULL") = () trailers: object(c_default="NULL") = () flags: int = 0 @@ -11886,7 +11886,7 @@ static PyObject * os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, Py_ssize_t count, PyObject *headers, PyObject *trailers, int flags) -/*[clinic end generated code: output=329ea009bdd55afc input=338adb8ff84ae8cd]*/ +/*[clinic end generated code: output=329ea009bdd55afc input=dcb026b94effa922]*/ #else /*[clinic input] os.sendfile @@ -11894,7 +11894,7 @@ os.sendfile out_fd: int in_fd: int offset as offobj: object - count: Py_ssize_t + count: Py_ssize_t(allow_negative=False) Copy count bytes from file descriptor in_fd to file descriptor out_fd. [clinic start generated code]*/ @@ -11902,12 +11902,22 @@ Copy count bytes from file descriptor in_fd to file descriptor out_fd. static PyObject * os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, Py_ssize_t count) -/*[clinic end generated code: output=ae81216e40f167d8 input=76d64058c74477ba]*/ +/*[clinic end generated code: output=ae81216e40f167d8 input=424df0949059ea5b]*/ #endif { Py_ssize_t ret; int async_err = 0; +#ifdef __APPLE__ + if(sbytes < 0) { + PyErr_SetString(PyExc_ValueError, + "count cannot be negative"); + return NULL; + } +#else + assert(count >= 0); +#endif + #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) #ifndef __APPLE__ off_t sbytes;