Repository navigation
Exception in ucs2lib_utf8_encoder in _bootstrap_python #94526
Copy link
Copy link
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 3, 2022 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.11only security fixesonly security fixes3.12only security fixesonly security fixes
on Sep 17, 2022 I created PR #97645 to fix the root issue.
I can reproduce the issue:
- Clone Python Git repository in a non-ASCII directory:
/home/vstinner/python/mainé(éis non-ASCII) - Build Python:
./configure --with-pydebug && make - make fails with:
ModuleNotFoundError: No module named 'encodings'
My locale encoding is
UTF-8, my LC_CTYPE locale isfr_FR.UTF-8.The problem is that the getpath_dirname() function of Modules/getpath.c encodes the Unicode path to UTF-8/strict using
sformat and PyArg_ParseTuple(), whereas a path can contain surrogate characters.The getpath_dirname() and getpath_basename() convert their Unicode input string to bytes just to be able to use
strrchr(path, SEP)since SEP is a bytes string. There is no need to convert these strings to bytes, whereas the conversion is the root issue here.- Clone Python Git repository in a non-ASCII directory:
- added a commit that references this issue
on Sep 30, 2022
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
I am building python in a directory that has non-ascii name on linux and get the following error:
The problem seems to be that the limited environment used to execute the precompiled
Modules/getpath.pydoes not have theencodingsmodule.I tracked the exception to a
PyImport_ImportModule("encodings");call inPython/codecs.cwhich is a consequence of aPyCodec_LookupErrorthat happens inucs2lib_utf8_encoderwhich I think gets called ingetpath_dirname.The original string is
/home/pgy/letöltések/cpython/_bootstrap_python, and the unicode objectucs2lib_utf8_encodergets as an argument is:Your environment
Linux hostname 5.15.44-1-lts #1 SMP Mon, 30 May 2022 13:45:47 +0000 x86_64 GNU/Linux