Repository navigation
gh-142782: Fix use-after-free in the zoneinfo strong cache - #159441
Open
tonghuaroot wants to merge 3 commits into
Open
tonghuaroot wants to merge 3 commits into
tonghuaroot wants to merge 3 commits into
Conversation
Comparing a lookup key against a cached key runs the key's __eq__, which can re-enter and call ZoneInfo.clear_cache(), freeing the node being compared; find_in_strong_cache() then dereferenced the freed node. Keep a reference to the node key during the comparison and bump a cache version counter on every mutation, so a lookup that observes a mutation during a comparison returns a miss instead of using a freed node.
tonghuaroot
requested review from
StanFromIreland and
pganssle
as code owners
October 15, 2026 02:59
maurycy
reviewed
Oct 15, 2026
Comment on lines
+1684
to
+1685
| klass(Stringy("America/Los_Angeles")) | ||
| klass(Stringy("America/Los_Angeles")) |
Contributor
There was a problem hiding this comment.
Do we need assertions here?
Suggested change
| klass(Stringy("America/Los_Angeles")) | |
| klass(Stringy("America/Los_Angeles")) | |
| zone1 = klass(Stringy("America/Los_Angeles")) | |
| zone2 = klass(Stringy("America/Los_Angeles")) | |
| self.assertIsNot(zone2, zone1) | |
| self.assertEqual(str(zone2), "America/Los_Angeles") |
Contributor
Author
|
good point, added the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
find_in_strong_cache()compares the lookup key against each cached key withPyObject_RichCompareBool(). Astrsubclass whose__eq__callsZoneInfo.clear_cache()frees the node being compared, and the traversal then dereferences the freed node (gh-142782).This keeps a reference to the node key during the comparison, and bumps a
strong_cache_versioncounter on every strong-cache mutation; if the version changes during a comparison, the lookup returns a miss instead of touching a possibly-freed node. This also addresses the false-negative / duplicate concern raised on the issue.Verified under
./configure --with-address-sanitizer: the reproducer and the newtest_strong_cache_reentrant_clearcrash without the fix and are clean with it; the fulltest_zoneinfosuite passes.