gh-155247: Use raw string content for the extensions cache key - #155249
Open
serhiy-storchaka wants to merge 3 commits into
Open
gh-155247: Use raw string content for the extensions cache key#155249serhiy-storchaka wants to merge 3 commits into
serhiy-storchaka wants to merge 3 commits into
Conversation
The key of the extensions cache was built with _PyUnicode_AsUTF8NoNUL(), so importing an extension module failed with UnicodeEncodeError if its path contained characters unencodable in UTF-8, e.g. surrogate escapes of an undecodable file name. The raw content of the strings is now used. The rejection of embedded null characters, which was a side effect of the UTF-8 encoding, is now explicit in the extension module loader. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
serhiy-storchaka
requested review from
FFY00,
brettcannon,
ericsnowcurrently,
kumaraditya303,
ncoghlan and
warsaw
as code owners
August 5, 2026 15:40
A loaded extension module cannot be removed on Windows, so the temporary directory is now removed with ignore_errors. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The key is hashed and compared as raw bytes, so the uninitialized padding of the header made lookups miss at random. Import the extension module in a subprocess: it stays loaded, and on Windows its file cannot be removed, so the temporary directory leaked.
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.
Importing an extension module failed with
UnicodeEncodeErrorif its path contained characters unencodable in UTF-8, e.g. surrogate escapes of a file name undecodable in the filesystem encoding. As a result, Python could not be built or run in a directory with such name.The key of the extensions cache was built with
_PyUnicode_AsUTF8NoNUL(). The raw content of the strings (UCS1, UCS2 or UCS4) is now used instead.The rejection of embedded null characters, which was a side effect of the UTF-8 encoding, is now explicit in the extension module loader.