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

Segfault in comparison between datetime.timezone.utc and pytz.utc #82096

Closed
TomAugspurger mannequin opened this issue Aug 22, 2019 · 10 comments
Closed

Segfault in comparison between datetime.timezone.utc and pytz.utc #82096

TomAugspurger mannequin opened this issue Aug 22, 2019 · 10 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes release-blocker type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@TomAugspurger
Copy link
Mannequin

TomAugspurger mannequin commented Aug 22, 2019

BPO 37915
Nosy @abalkin, @ned-deily, @ambv, @serhiy-storchaka, @pganssle, @pablogsal, @miss-islington, @tirkarthi, @TomAugspurger
PRs
  • bpo-37915: Fix comparison between tzinfo objects and timezone objects #15390
  • [3.8] bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390) #15399
  • [3.7] bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390) #15417
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-08-23.10:12:53.927>
    created_at = <Date 2019-08-22.11:18:39.483>
    labels = ['3.7', '3.8', '3.9', 'type-crash', 'release-blocker']
    title = 'Segfault in comparison between datetime.timezone.utc and pytz.utc'
    updated_at = <Date 2019-08-23.11:53:21.433>
    user = 'https://github.com/TomAugspurger'

    bugs.python.org fields:

    activity = <Date 2019-08-23.11:53:21.433>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-08-23.10:12:53.927>
    closer = 'pablogsal'
    components = []
    creation = <Date 2019-08-22.11:18:39.483>
    creator = 'tomaugspurger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37915
    keywords = ['3.8regression']
    message_count = 10.0
    messages = ['350184', '350186', '350189', '350194', '350195', '350196', '350227', '350267', '350270', '350277']
    nosy_count = 9.0
    nosy_names = ['belopolsky', 'ned.deily', 'lukasz.langa', 'serhiy.storchaka', 'p-ganssle', 'pablogsal', 'miss-islington', 'xtreak', 'tomaugspurger']
    pr_nums = ['15390', '15399', '15417']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue37915'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @TomAugspurger
    Copy link
    Mannequin Author

    TomAugspurger mannequin commented Aug 22, 2019

    The following crashes with Python 3.8b3

    import sys
    import pytz
    import datetime
    
    print(sys.version_info)
    print(pytz.__version__)
    print(datetime.timezone.utc == pytz.utc)
    

    When run with -X faulthandler, I see

    sys.version_info(major=3, minor=8, micro=0, releaselevel='beta', serial=3)
    2019.2
    Fatal Python error: Segmentation fault
    
    Current thread 0x00000001138dc5c0 (most recent call first):
      File "foo.py", line 8 in <module>
    Segmentation fault: 11
    

    @TomAugspurger TomAugspurger mannequin added 3.8 only security fixes type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 22, 2019
    @tirkarthi
    Copy link
    Member

    I am adding 3.8 regression since the code works with 3.7 though it involves pytz.

    @tirkarthi tirkarthi changed the title Segfault in comparison between datetime.timezone.utc and putz.utc Segfault in comparison between datetime.timezone.utc and pytz.utc Aug 22, 2019
    @tirkarthi
    Copy link
    Member

    Seems this is due to bpo-37685 (dde944f) on bisecting datetime related changes. Adding Serhiy. I guess this could be marked as release blocker.

    Here is a simplified reproducer on extracting pytz.utc source [0] which is an object of simple subclass of datetime.tzinfo :

    import sys
    import datetime
    
    print(sys.version)
    class UTC(datetime.tzinfo):
        pass
    
    print(datetime.timezone.utc == UTC())
    datetime.timezone.utc == datetime.tzinfo() # This also segfaults without a subclass and should be False

    # Segfaults

    ➜ cpython git:(dde944f) git checkout dde944f && make -s -j4 > /dev/null
    HEAD is now at dde944f bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
    ➜ cpython git:(dde944f) ./python.exe ../backups/bpo37915.py
    3.8.0b3+ (tags/v3.8.0b3-30-gdde944f9df:dde944f9df, Aug 22 2019, 17:55:14)
    [Clang 7.0.2 (clang-700.1.81)]
    [1] 33988 segmentation fault ./python.exe ../backups/bpo37915.py

    # Commit before works fine

    ➜ cpython git:(dde944f) git checkout dde944f~1 && make -s -j4 > /dev/null
    Previous HEAD position was dde944f bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
    HEAD is now at 4e402d3 Correct description of HTTP status code 308. (GH-15098)
    ➜ cpython git:(4e402d3) ./python.exe ../backups/bpo37915.py
    3.8.0b3+ (tags/v3.8.0b3-30-gdde944f9df:dde944f9df, Aug 22 2019, 17:55:14)
    [Clang 7.0.2 (clang-700.1.81)]
    False

    [0] https://github.com/stub42/pytz/blob/62f872054dde69e5c510094093cd6e221d96d5db/src/pytz/__init__.py#L256

    @TomAugspurger
    Copy link
    Mannequin Author

    TomAugspurger mannequin commented Aug 22, 2019

    Thanks for debugging this Karthikeyan and for the quick fix Pablo!

    @pablogsal
    Copy link
    Member

    This is due to an incorrect type check in the timezone_richcompare, it should be a comparison against PyDateTime_TimeZoneType not against PyDateTime_TZInfoType. The segfault is due to an invalid casting to PyDateTime_TimeZoneType (the child) from the parent (PyDateTime_TZInfoType).

    @pablogsal
    Copy link
    Member

    Thanks, Tom and Karthikeyan for the finding and the debugging :)

    @miss-islington
    Copy link
    Contributor

    New changeset 4be11c0 by Miss Islington (bot) (Pablo Galindo) in branch 'master':
    bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)
    4be11c0

    @miss-islington
    Copy link
    Contributor

    New changeset 5c77730 by Miss Islington (bot) in branch '3.8':
    bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)
    5c77730

    @pablogsal
    Copy link
    Member

    New changeset 1b1796d by Pablo Galindo in branch '3.7':
    [3.7] bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390) (GH-15417)
    1b1796d

    @pablogsal pablogsal added 3.7 (EOL) end of life 3.9 only security fixes labels Aug 23, 2019
    @ned-deily
    Copy link
    Member

    (Removing “3.7regression” as the problematic change for 3.7 had not yet been released.)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes release-blocker type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants