Skip to content
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

Incorrect argument type for str() crashes the interpreter #122888

Closed
pschanely opened this issue Aug 10, 2024 · 3 comments · Fixed by #122889
Closed

Incorrect argument type for str() crashes the interpreter #122888

pschanely opened this issue Aug 10, 2024 · 3 comments · Fixed by #122889
Assignees
Labels
release-blocker type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@pschanely
Copy link
Contributor

pschanely commented Aug 10, 2024

Crash report

What happened?

Using a byte string for the encoding parameter of str() results in a crash (instead of the expected TypeError):

str(b"hello", b"ascii")

Here is the output I get on macos, 3.13.0b4:

% python
Python 3.13.0b4 (main, Jul 24 2024, 12:21:52) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> str(b"hello", b"ascii")
Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set
Python runtime state: initialized
TypeError: str() argument 'encoding' must be str, not bytes

The above exception was the direct cause of the following exception:

SystemError: <class 'str'> returned a result with an exception set

Current thread 0x00000002064b0c00 (most recent call first):
  File "<python-input-0>", line 1 in <module>
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/code.py", line 91 in runcode
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/_pyrepl/console.py", line 200 in runsource
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/code.py", line 303 in push
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/_pyrepl/simple_interact.py", line 156 in run_multiline_interactive_console
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/_pyrepl/main.py", line 57 in interactive_console
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/_pyrepl/__main__.py", line 6 in <module>
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/runpy.py", line 88 in _run_code
  File "/Users/phillipschanely/.pyenv/versions/3.13.0b4-debug/lib/python3.13/runpy.py", line 198 in _run_module_as_main
zsh: abort      python

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Output from running 'python -VV' on the command line:

Python 3.13.0b4 (main, Jul 24 2024, 12:21:52) [Clang 15.0.0 (clang-1500.3.9.4)]

Linked PRs

@pschanely pschanely added the type-crash A hard crash of the interpreter, possibly with a core dump label Aug 10, 2024
@JelleZijlstra JelleZijlstra self-assigned this Aug 10, 2024
@ZeroIntensity
Copy link
Member

Note that the crash only occurs on debug builds.

@JelleZijlstra
Copy link
Member

Thanks, I submitted a fix. The issue goes back to at least 3.13.0b2 but I didn't look for the exact culprit.

On release builds it throws a SystemError instead. When pure Python code raises SystemError it is almost always a bug.

@JelleZijlstra
Copy link
Member

Marking as a release blocker to make sure this gets merged before the next 3.13 RC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-blocker type-crash A hard crash of the interpreter, possibly with a core dump
Projects
Development

Successfully merging a pull request may close this issue.

3 participants