Skip to content

🐛 fix(activate): preserve Tcl library path bytes - #3645

Merged
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:fix/tcl-library-codec-174
Nov 20, 2026
Merged

gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:fix/tcl-library-codec-174

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Activation generation at the merge base copied Tcl library text into scripts without checking whether its UTF-8 spelling matched the original path bytes. Under a legacy locale, activation could replace a user's working TCL_LIBRARY with a different directory and make a later Tcl program load files from that directory. The activators now include a non-ASCII path only when the current environment supplies the same bytes. This addresses draft advisory ANT-2026-174OWDGY.

Tcl path text can lose its byte spelling

python-discovery queries info library when TCL_LIBRARY is set. Tcl checks that variable first for its startup library. The returned text can differ from the variable's original byte spelling in a legacy locale; Python's UTF-8 mode can also be active in the C locale. The template writer encoded that text as UTF-8. The destination check added in #3412 compares only the environment destination, so an ASCII destination does not stop this path change.

Activation checks the original bytes

The shared library path check keeps ASCII paths and Windows behavior. For a non-ASCII POSIX path, it compares the text's UTF-8 bytes with the corresponding raw environment variable. If they differ or the variable is absent, the bash template's empty-value condition leaves the shell value alone. Bash, fish, nushell, and xonsh use the same check rather than replacing the base class values with unverified text. On POSIX, Xonsh decodes the original UTF-8 bytes at activation, using the active filesystem codec so a later locale change does not alter the exported path bytes.

flowchart LR
    D[Tcl library text] --> B[Before: write text as UTF-8]
    B --> X[Activation may use different path bytes]
    D --> C{Now: ASCII or Windows?}
    C -- yes --> W[Write path]
    C -- no --> E{UTF-8 bytes match current variable?}
    E -- yes --> W
    E -- no --> K[Leave shell value alone]
    classDef bad fill:#ffd6d6,stroke:#c1121f,color:#5c0000;
    classDef ok fill:#d8f3dc,stroke:#2d6a4f,color:#1b4332;
    class B,X bad;
    class C,E,W,K ok;
Loading

Behavior changes

A non-ASCII TCL_LIBRARY already set in a UTF-8 environment remains available after activation. If the path text cannot be tied to the current variable, activation preserves the shell's existing TCL_LIBRARY; when it is unset, Tcl performs its normal library search. The same rule applies to generated TK_LIBRARY values. A cached non-ASCII path is no longer restored when its source environment variable is absent. ASCII library paths and Windows generation keep their previous behavior.

Reported by oss-scanner: ANT-2026-174OWDGY.

Tcl can decode a library path with a different codec than the one used
for activation scripts. Include a non-ASCII path only when its UTF-8
bytes match the current environment value. This keeps valid UTF-8 paths
while avoiding a different directory after activation.
@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
@gaborbernat
gaborbernat merged commit 557cd60 into pypa:main Nov 20, 2026
86 of 91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug security Fixes a vulnerability or hardens the supply chain, CI or release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant