8000 sys.remote_exec() doesn't work with non-UTF-8 paths · Issue #133886 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

sys.remote_exec() doesn't work with non-UTF-8 paths #133886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serhiy-storchaka opened this issue May 11, 2025 · 0 comments
Closed

sys.remote_exec() doesn't work with non-UTF-8 paths #133886

serhiy-storchaka opened this issue May 11, 2025 · 0 comments
Assignees
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member
serhiy-storchaka commented May 11, 2025

Bug report

There are two symptoms:

  1. It does not work with non-ASCII names in non-UTF-8 locale. All related test_sys tests are failed on in non-UTF-8 locale. For example:
    $ LC_ALL=uk_UA ./python -m test -vuall test_sys -m test_remote_exec
    ======================================================================
    ERROR: test_remote_exec (test.test_sys.TestRemoteExec.test_remote_exec)
    Test basic remote exec functionality
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/test/test_sys.py", line 2078, in test_remote_exec
        returncode, stdout, stderr = self._run_remote_exec_test(script)
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
      File "/home/serhiy/py/cpython/Lib/test/test_sys.py", line 2052, in _run_remote_exec_test
        sys.remote_exec(proc.pid, script_path)
        ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
    FileNotFoundError: Script file does not exist
    
    ----------------------------------------------------------------------
    
  2. Even in UTF-8 locale it fails if the path contains non-UTF-8 bytes.

The issue is twofold. On one side, sys.remote_exec() encodes the path to UTF-8 (even if the bytes path was decoded using the filesystem encoding). It fails because os.access() can't find file using the wrong path. It can accidentally success if other file exists with such path. On other side, PyFile_OpenFile() which interprets the path as UTF-8 is used to open the file.

Linked PRs

@serhiy-storchaka serhiy-storchaka self-assigned this May 11, 2025
@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label May 11, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 11, 2025
It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
@serhiy-storchaka serhiy-storchaka added 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels May 11, 2025
serhiy-storchaka added a commit that referenced this issue May 13, 2025
It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 13, 2025
…133887)

It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
(cherry picked from commit c09cec5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue May 13, 2025
… (GH-133963)

It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
(cherry picked from commit c09cec5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant
0