classification
Title: Segfault in comparison between datetime.timezone.utc and pytz.utc
Type: crash Stage: resolved
Components: Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, lukasz.langa, miss-islington, ned.deily, p-ganssle, pablogsal, serhiy.storchaka, tomaugspurger, xtreak
Priority: release blocker Keywords: 3.8regression

Created on 2019-08-22 11:18 by tomaugspurger, last changed 2019-08-23 11:53 by ned.deily. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15390 merged pablogsal, 2019-08-22 15:12
PR 15399 merged miss-islington, 2019-08-22 19:24
PR 15417 merged pablogsal, 2019-08-23 09:54
Messages (10)
msg350184 - (view) Author: Tom Augspurger (tomaugspurger) Date: 2019-08-22 11:18
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
```
msg350186 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-08-22 11:45
I am adding 3.8 regression since the code works with 3.7 though it involves pytz.
msg350189 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-08-22 12:34
Seems this is due to issue37685 (dde944f9df) 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:(dde944f9df) git checkout dde944f9df && make -s -j4 > /dev/null
HEAD is now at dde944f9df bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
➜  cpython git:(dde944f9df) ./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:(dde944f9df) git checkout dde944f9df~1 && make -s -j4 > /dev/null
Previous HEAD position was dde944f9df bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
HEAD is now at 4e402d37eb Correct description of HTTP status code 308. (GH-15098)
➜  cpython git:(4e402d37eb) ./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
msg350194 - (view) Author: Tom Augspurger (tomaugspurger) Date: 2019-08-22 15:19
Thanks for debugging this Karthikeyan and for the quick fix Pablo!
msg350195 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-22 15:20
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).
msg350196 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-22 15:21
Thanks, Tom and Karthikeyan for the finding and the debugging :)
msg350227 - (view) Author: miss-islington (miss-islington) Date: 2019-08-22 19:24
New changeset 4be11c009abe88175fa164b45e4838e7267dfa97 by Miss Islington (bot) (Pablo Galindo) in branch 'master':
bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)
https://github.com/python/cpython/commit/4be11c009abe88175fa164b45e4838e7267dfa97
msg350267 - (view) Author: miss-islington (miss-islington) Date: 2019-08-23 08:48
New changeset 5c77730300c0358d7bebd2bb39ea5d10222a3d9a by Miss Islington (bot) in branch '3.8':
bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)
https://github.com/python/cpython/commit/5c77730300c0358d7bebd2bb39ea5d10222a3d9a
msg350270 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-23 10:12
New changeset 1b1796df3a4292067a174faa11b1a852f79e98e3 by Pablo Galindo in branch '3.7':
[3.7] bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390) (GH-15417)
https://github.com/python/cpython/commit/1b1796df3a4292067a174faa11b1a852f79e98e3
msg350277 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-08-23 11:53
(Removing “3.7regression” as the problematic change for 3.7 had not yet been released.)
History
Date User Action Args
2019-08-23 11:53:21ned.deilysetkeywords: - 3.7regression

messages: + msg350277
2019-08-23 10:12:53pablogsalsetstatus: open -> closed

nosy: + ned.deily
versions: + Python 3.7, Python 3.9
keywords: + 3.7regression, - patch
resolution: fixed
stage: patch review -> resolved
2019-08-23 10:12:34pablogsalsetmessages: + msg350270
2019-08-23 09:54:56pablogsalsetpull_requests: + pull_request15118
2019-08-23 08:48:45miss-islingtonsetmessages: + msg350267
2019-08-22 19:24:36miss-islingtonsetpull_requests: + pull_request15107
2019-08-22 19:24:31miss-islingtonsetnosy: + miss-islington
messages: + msg350227
2019-08-22 18:43:05pablogsalsetpriority: normal -> release blocker
nosy: + lukasz.langa
2019-08-22 15:21:06pablogsalsetmessages: + msg350196
2019-08-22 15:20:25pablogsalsetnosy: + pablogsal
messages: + msg350195
2019-08-22 15:19:22tomaugspurgersetmessages: + msg350194
2019-08-22 15:12:46pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15100
2019-08-22 12:34:33xtreaksetnosy: + serhiy.storchaka
messages: + msg350189
2019-08-22 11:46:19xtreaksettitle: Segfault in comparison between datetime.timezone.utc and putz.utc -> Segfault in comparison between datetime.timezone.utc and pytz.utc
2019-08-22 11:45:51xtreaksetkeywords: + 3.8regression
nosy: + p-ganssle, xtreak, belopolsky
messages: + msg350186

2019-08-22 11:18:39tomaugspurgercreate