external/python3/UnpackedTarball_python3.mk | 1 external/python3/init-sys-streams-cant-initialize-stdin.patch.0 | 43 ++++++++++ 2 files changed, 44 insertions(+)
New commits: commit d261db7fb35e4851b92dc0456aaaa48a09826785 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Mar 27 14:45:59 2024 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Mar 28 21:50:31 2024 +0100 python exits on initialization if fd 0 is a dir which can happen if stdin was closed and the next open was of a dir. Later python checks for is_valid_fd, but an invalid fd is not fatal for stdin, etc and it just return an empty stdin wrapper, so move this check lower and do the same for a dir. Change-Id: Iaf8a48927b49408577ae7a781dfc6e0255a940cb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165397 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/external/python3/UnpackedTarball_python3.mk b/external/python3/UnpackedTarball_python3.mk index 93cb9015c9a6..6eaa4ca82784 100644 --- a/external/python3/UnpackedTarball_python3.mk +++ b/external/python3/UnpackedTarball_python3.mk @@ -28,6 +28,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,python3,\ external/python3/darwin.patch.0 \ external/python3/macos-11.patch.0 \ external/python3/tsan.patch.0 \ + external/python3/init-sys-streams-cant-initialize-stdin.patch.0 \ )) ifneq ($(filter DRAGONFLY FREEBSD LINUX NETBSD OPENBSD SOLARIS,$(OS)),) diff --git a/external/python3/init-sys-streams-cant-initialize-stdin.patch.0 b/external/python3/init-sys-streams-cant-initialize-stdin.patch.0 new file mode 100644 index 000000000000..61b2464ab4b8 --- /dev/null +++ b/external/python3/init-sys-streams-cant-initialize-stdin.patch.0 @@ -0,0 +1,43 @@ +--- Python/pylifecycle.c 2024-03-27 14:34:43.905367358 +0000 ++++ Python/pylifecycle.c 2024-03-27 14:40:16.339134322 +0000 +@@ -1723,6 +1723,20 @@ + if (!is_valid_fd(fd)) + Py_RETURN_NONE; + ++ /* Check that stdin, etc is not a directory ++ Using shell redirection, you can redirect stdin to a directory, ++ crashing the Python interpreter. Catch this common mistake here ++ and output a useful error message. Note that under MS Windows, ++ the shell already prevents that. */ ++#ifndef MS_WINDOWS ++ struct _Py_stat_struct sb; ++ if (_Py_fstat_noraise(fd, &sb) == 0 && ++ S_ISDIR(sb.st_mode)) { ++ // "name" is a directory, cannot continue ++ Py_RETURN_NONE; ++ } ++#endif ++ + /* stdin is always opened in buffered mode, first because it shouldn't + make a difference in common use cases, second because TextIOWrapper + depends on the presence of a read1() method which only exists on +@@ -1854,19 +1868,6 @@ + PyStatus res = _PyStatus_OK(); + PyConfig *config = &interp->config; + +- /* Check that stdin is not a directory +- Using shell redirection, you can redirect stdin to a directory, +- crashing the Python interpreter. Catch this common mistake here +- and output a useful error message. Note that under MS Windows, +- the shell already prevents that. */ +-#ifndef MS_WINDOWS +- struct _Py_stat_struct sb; +- if (_Py_fstat_noraise(fileno(stdin), &sb) == 0 && +- S_ISDIR(sb.st_mode)) { +- return _PyStatus_ERR("<stdin> is a directory, cannot continue"); +- } +-#endif +- + /* Hack to avoid a nasty recursion issue when Python is invoked + in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ + if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) {
