Skip to content

python -m pdb <utf-8 encoding file.py> return UnicodeDecodeError on Windows 8.1/10 (code page 936) #103578

Description

@xond

how to replicate the issue

Python 3.11.3/3.11.2/3.11.1/3.11.0 (python-3.11.3-amd64.exe etc)
Microsoft Windows [Version 10.0.19044.2130] (Active code page: 936)

tmp.py

#coding:utf-8
print("中文")

python -m pdb tmp.py

Traceback (most recent call last):
  File "C:\Users\xond\AppData\Local\Programs\Python\Python311\Lib\pdb.py", line 1774, in main
    pdb._run(target)
  File "C:\Users\xond\AppData\Local\Programs\Python\Python311\Lib\pdb.py", line 1652, in _run
    self.run(target.code)
             ^^^^^^^^^^^
  File "C:\Users\xond\AppData\Local\Programs\Python\Python311\Lib\pdb.py", line 167, in code
    return f"exec(compile({fp.read()!r}, {self!r}, 'exec'))"
                           ^^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 28: illegal multibyte sequence
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> c:\users\xond\appdata\local\programs\python\python311\lib\pdb.py(167)code()
-> return f"exec(compile({fp.read()!r}, {self!r}, 'exec'))"

Linked PRs

Activity

  1. gaogaotiantian commented on Apr 16, 2023

    @gaogaotiantian
    Member

    This is an encoding issue - we can simply use io.read_code to avoid it, as we are always expecting the read code with pdb. PR is done with the regression test.

  2. added a commit that references this issue on Apr 26, 2023
  3. added a commit that references this issue on Apr 26, 2023
  4. added a commit that references this issue on Apr 26, 2023
  5. added a commit that references this issue on Apr 26, 2023
  6. hauntsaninja commented on Apr 26, 2023

    @hauntsaninja
    Contributor

    Thanks again!

  7. zooba commented on Apr 27, 2023

    @zooba
    Member

    This is a case that always should've gone through io.open_code, and people may be caught out by having code execution bypass that path.

    We should backport to 3.8+

  8. zooba commented on Apr 27, 2023

    @zooba
    Member

    I take that back - 3.8-3.10 were already fixed, it was a change in 3.11 that regressed this. So no backports required.

  9. added
    3.11only security fixes
    3.12only security fixes
    and removed on Apr 27, 2023
  10. hauntsaninja commented on Apr 27, 2023

    @hauntsaninja
    Contributor

    Thanks for checking, sorry I could have more explicitly mentioned this! :-)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions