python / python/cpython

Crash in _interpreters.create() when config string has an unpaired surrogate

Đang mở
#148,798 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

interpreter-core topic-subinterpreters type-crash
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Crash Report

Crash description

_interpreters.create() segfaults when the config object exposes a string attribute (e.g. gil) containing an unpaired surrogate. The C helper _config_dict_copy_str calls PyUnicode_AsUTF8() and passes the result straight to strncpy() without a NULL check. When the string can't be UTF-8 encoded, PyUnicode_AsUTF8() returns NULL and sets UnicodeEncodeError, but the NULL then reaches strncpy and the interpreter crashes.

Lone surrogates are reachable from pure Python ('\udc80', chr(0xDC80)), and also show up naturally via surrogateescape — e.g. filenames, env vars, or argv with non-UTF-8 bytes that get forwarded into a config dict.

Related precedent: gh-126221 (same module, same module crash class from pure Python input).

Reproducer

import _interpreters

class BadConfig:
    use_main_obmalloc = False
    allow_fork = False
    allow_exec = False
    allow_threads = False
    allow_daemon_threads = False
    check_multi_interp_extensions = False
    own_gil = True
    gil = 'own\udc80'

_interpreters.create(BadConfig())

Expected: UnicodeEncodeError.
Actual: segfault (exit 139).

Reproduced on 3.14.3 and current main.

Error messages

zsh: segmentation fault  python3 repro.py

Your environment

  • CPython 3.14.3 and main (Python/interpconfig.c unchanged since gh-117170)
  • macOS / Linux (encoding-independent; the bug is in C)

Linked PRs

(fix ready, will link once this is filed)

Linked PRs
  • gh-148799

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Kiểm tra Python/interpconfig.c, đặc biệt là _config_dict_copy_str, và chạy trình tái hiện BadConfig được cung cấp với một surrogate không đi đôi. Hoàn thành khi đầu vào tạo ra UnicodeEncodeError thay vì gây ra segfault; gh-148799 đã được liên kết ως bản sửa lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, python
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.