Skip to content

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

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

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

Activity

added a commit that references this issue on May 11, 2025

pythongh-133886: Fix sys.remote_exec() for non-UTF-8 paths

added
3.14bugs and security fixes
3.15new features, bugs and security fixes
on May 11, 2025
added a commit that references this issue on May 13, 2025

gh-133886: Fix sys.remote_exec() for non-UTF-8 paths (GH-133887)

c09cec5
added a commit that references this issue on May 13, 2025

pythongh-133886: Fix sys.remote_exec() for non-UTF-8 paths (pythonGH-…

added a commit that references this issue on May 13, 2025

[3.14] gh-133886: Fix sys.remote_exec() for non-UTF-8 paths (GH-133887)…

f0a7a6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.14bugs and security fixes3.15new features, bugs and security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    sys.remote_exec() doesn't work with non-UTF-8 paths · Issue #133886 · python/cpython

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant