Skip to content

🐛 fix(activation): preserve Tcl/Tk and xonsh paths across codecs - #3743

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:restore/3645-tcl-library-codec
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:restore/3645-tcl-library-codec

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Activation templates copied Tcl library path text into generated scripts without checking whether its UTF-8 spelling matched the original path bytes. Xonsh activation could also reinterpret path or prompt text under a different source or filesystem codec. The generated scripts now preserve verifiable library paths and reconstruct Xonsh values without changing their path bytes. This addresses draft advisories ANT-2026-174OWDGY and ANT-2026-Y91OJFTQ.

Tcl and Tk library paths

Python discovery reads Tcl's reported library path, and Tcl consults TCL_LIBRARY for its startup library. In a legacy POSIX locale, the reported text can differ from the environment variable's original bytes. During script generation, the shared activation check includes a non-ASCII Tcl or Tk path only when its UTF-8 bytes match the current variable. ASCII paths and Windows paths keep their prior behavior. If the bytes cannot be verified, sourcing the script leaves the shell's existing library value alone.

Xonsh source and filesystem codecs

The Xonsh template renders prompts and other text that could change meaning under UTF-7 source decoding as ASCII expressions. On POSIX it records non-ASCII environment and library paths as UTF-8 bytes. The sourced activator decodes those paths with the active filesystem codec and checks that they round-trip. This keeps VIRTUAL_ENV, PATH, PKG_CONFIG_PATH, Tcl and Tk values, and the prompt tied to the intended environment across the tested codec changes.

Behavior changes

An existing non-ASCII TCL_LIBRARY from a matching UTF-8 environment remains available after activation. If its source bytes cannot be verified, activation leaves it alone. Tcl uses its normal search when the variable is unset. The same check applies to TK_LIBRARY, including a Tk path derived from a verified Tcl source. If the Xonsh filesystem codec cannot represent the destination, activation fails and the current environment stays active. Xonsh omits optional library paths it cannot verify. Existing environments need recreated activation scripts to receive these changes.

Fixes #3631. Reported by oss-scanner: ANT-2026-174OWDGY, ANT-2026-PQW92I38, ANT-2026-Y91OJFTQ.

@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
Tcl library paths and Xonsh activation values could change when a script
was sourced under a different text or filesystem codec. Check recorded
Tcl bytes, emit encoding-independent Xonsh source, and refuse path text
that cannot round-trip through the active filesystem codec.

Refs pypa#3743
Refs pypa#3708
Refs pypa#3709
Refs pypa#3729
Refs pypa#3717
@gaborbernat gaborbernat changed the title 🐛 fix(activate): preserve Tcl library path bytes 🐛 fix(activation): preserve path bytes across codecs Nov 20, 2026
@gaborbernat
gaborbernat force-pushed the restore/3645-tcl-library-codec branch from a252d6f to b99286a Compare November 20, 2026 15:31
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 17:27
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 20:27
Validate the next environment's path while the current environment is
still active. A Big5 session can then keep using its interpreter when it
cannot represent the destination.
@gaborbernat gaborbernat changed the title 🐛 fix(activation): preserve path bytes across codecs 🐛 fix(activation): preserve Tcl/Tk and xonsh paths across codecs Nov 20, 2026
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 21:28
@gaborbernat
gaborbernat merged commit 3dac6a8 into pypa:main Nov 20, 2026
91 checks passed
@gaborbernat
gaborbernat deleted the restore/3645-tcl-library-codec branch November 23, 2026 18:12
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.

Xonsh activation selects wrong PATH directory after locale change

1 participant