Repository navigation
gh-163188: Fix use-after-free in zoneinfo clear_cache() re-entered from a key's __del__ - #163218
Open
abedalawieh wants to merge 1 commit into
Open
abedalawieh wants to merge 1 commit into
abedalawieh wants to merge 1 commit into
Conversation
…red from a key's __del__
abedalawieh
requested review from
StanFromIreland and
pganssle
as code owners
December 5, 2026 21:36
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.
clear_strong_cache()freed the strong cache's linked list whilestate->ZONEINFO_STRONG_CACHEstill pointed at it. Releasing a node's key or zone can run arbitrary code. If astrsubclass key's__del__callsZoneInfo.clear_cache(), the nested call frees the same nodes again, and the outer loop then reads the freed nodes.The fix detaches the list from the module state before freeing it, so a re-entrant call only sees an empty cache. The other paths that free nodes (
eject_from_strong_cache()and the eviction inupdate_strong_cache()) already unlink the nodes before releasing them.The new test in
test_zoneinfo(it runs for both the C and Python implementations) checks that__del__ran duringclear_cache(). Without the fix, a--with-pydebug --with-address-sanitizerbuild aborts on a negative reference count. With the fix,test_zoneinfopasses on that build.zoneinfo: Heap use-after-free and double-free inclear_strong_cache()via re-entrant key__del__#163188