python / python/cpython

Segfault from `zoneinfo` with custom DateTime class

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

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

extension-modules type-crash
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Crash report

What happened?

Here's a minimal reproducer

import zoneinfo
from datetime import date


class MyDateTime:
    def __init__(
        self,
        year: int,
        month: int,
        day: int,
        hour: int = 0,
        minute: int = 0,
        second: int = 0,
    ) -> None:
        self.ordinal = date(year, month, day).toordinal()
        self.hour = hour
        self.minute = minute
        self.second = second

    def toordinal(self) -> int:
        return self.ordinal


def whoopsie():
    tz_berlin = zoneinfo.ZoneInfo("Europe/Berlin")
    dt = MyDateTime(1995, 9, 2, 14, 34, 56)
    print(tz_berlin.utcoffset(dt), flush=True)

If I run whoopsie, I get one of the following outcomes:

  • It prints 02:00:00
  • It prints 01:00:00
  • It prints 00:53:28
  • It segfaults
<project dir>/venv313/bin/python -X dev <project dir>/segfault.py 
Fatal Python error: Segmentation fault

Current thread 0x00007fd62be47b80 (most recent call first):
 File "<project dir>/segfault.py", line 27 in whoopsie
 File "<project dir>/segfault.py", line 34 in <module>

I've tried running the test in a loop and it seems to always spit out the same result within a single run. So I assume some global state, memory layout, or or such is involved.

CPython versions tested on:

3.9, 3.13

Operating systems tested on:

Linux

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

Python 3.13.0 (main, Oct 10 2024, 13:32:18) [GCC 11.4.0]

Linked PRs
  • gh-125345
  • gh-125824
  • gh-139132

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

Bắt đầu với reproducer tối giản trong phần nội dung issue và chạy nó trên các phiên bản CPython được liệt kê để xác nhận sự cố crash và các offset không nhất quán. Sau đó đọc các PR được liên kết gh-125345, gh-125824 và gh-139132; công việc hoàn tất khi reproducer không còn gây ra segmentation fault và tạo ra kết quả ổn định, chính xác.

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

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
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.