Skip to content

gh-125318: Prevent segfaults when zoneinfo is used with "false friends" - #139132

Open
pganssle wants to merge 7 commits into
python:mainfrom
pganssle:zoneinfo_false_friends
Open

pganssle wants to merge 7 commits into
python:mainfrom
pganssle:zoneinfo_false_friends

Conversation

@pganssle

@pganssle pganssle commented Sep 18, 2025 •

Copy link
Copy Markdown
Member

Fixes #125318.

I think this can be backported to bugfix branches, since it just prevents segfaults. It might make things slower in some situations for people who have "false friend" classes that happen to have the same memory layout as datetime but that is not really a supported mode of operation anyway, we're really just fixing this because you shouldn't be able to crash the interpreter from pure Python code.

@pganssle

Copy link
Copy Markdown
Member Author

Not sure who might want to review this, maybe @StanFromIreland or @serhiy-storchaka or @ZeroIntensity?

@serhiy-storchaka
serhiy-storchaka self-requested a review September 19, 2025 09:48
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 29, 2026
Reject fold=2 before it can reach the transition array, and use the
correct format specifier for the long fold value. Match the datetime
year error message and use MAXYEAR for the upper bound.

Add regression tests for invalid folds and years, conversion errors,
and valid boundary values.
@pganssle
pganssle force-pushed the zoneinfo_false_friends branch from 4e29a95 to f6c77dd Compare October 20, 2026 18:41

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nits, otherwise LGTM.

Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Misc/NEWS.d/next/Library/2025-09-18-16-40-18.gh-issue-125318.JzZysW.rst Outdated
Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py Outdated
Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py Outdated
@@ -446,6 +447,52 @@ def __eq__(self, other):
class CZoneInfoTest(ZoneInfoTest):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have the Python implementation consistent, but backporting that would be troublesome so that can be left to a follow up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The footprint is actually pretty small, so I included it here. If you don't think it's backportable I can move it to a new PR.

Comment thread Modules/_zoneinfo.c Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault from zoneinfo with custom DateTime class

4 participants