Skip to content

🐛 fix(activate): preserve Tcl and Tk paths - #3708

Closed
gaborbernat wants to merge 28 commits into
pypa:mainfrom
gaborbernat:fix/tcl-library-followup-174
Closed

gaborbernat wants to merge 28 commits into
pypa:mainfrom
gaborbernat:fix/tcl-library-followup-174

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

PR #3645 verified Tcl library bytes when generating activation scripts, but its Xonsh script still embedded a Unicode literal. Sourcing that script under a different POSIX locale could export different path bytes. Xonsh now reconstructs the verified bytes with its active filesystem codec. The follow-up also restores non-ASCII Tk paths derived from a verified Tcl source. This follows draft advisory ANT-2026-174OWDGY.

Xonsh activation across locales

Xonsh's ASCII literal quoting kept the generated script readable, but preserved the path as Unicode text. A later legacy locale could encode that text to different bytes on export. The new substitution embeds the UTF-8 bytes verified during generation and decodes them when sourced, using the active filesystem codec. ASCII paths and Windows Unicode paths retain their earlier rendering.

flowchart LR
    V[Verified UTF-8 path bytes] --> O[Old Xonsh Unicode literal]
    O --> M[Later locale may export different bytes]
    V --> N[New bytes literal]
    N --> D[Decode with active filesystem codec]
    D --> S[Export original bytes]
    classDef bad fill:#ffd6d6,stroke:#c1121f,color:#5c0000;
    classDef ok fill:#d8f3dc,stroke:#2d6a4f,color:#1b4332;
    class O,M bad;
    class N,D,S ok;
Loading

Derived Tk paths

Python-discovery can derive a Tk library path from Tcl when TK_LIBRARY is unset. The merged check dropped non-ASCII derived paths in that case. The follow-up retains one when the raw TCL_LIBRARY bytes match the recorded Tcl path and the derived Tk path encodes to the same UTF-8 bytes that the script will write. An explicit TK_LIBRARY still requires its own byte match.

GraalPy FIFO test gate

PR #3662 found that GraalPy does not expose os.mkfifo, so the FIFO metadata test failed before reaching its assertions. This branch includes its capability guard, allowing the test to run on interpreters that provide FIFOs and skip where they are unavailable. The combined branch lets the GraalPy and PyPy suites check the Tcl fix without either merged regression blocking the other.

Test coverage

A Xonsh subprocess test checks the exported TCL_LIBRARY bytes after activation in a C locale. Windows generation checks that non-ASCII Tcl and Tk paths remain Unicode literals; I also ran it with legacy filesystem encoding in the Windows VM. The Tcl discovery integration test from #3645 now runs only on CPython: PyPy reports its bundled Tcl library path rather than the test's temporary TCL_LIBRARY directory, which caused the PyPy 3.11 CI failure.

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

Replaces #3660 after its merge was reverted.

gaborbernat and others added 28 commits November 19, 2026 22:36
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Pin the pre-commit hook to [simplint
0.14.2](https://github.com/gaborbernat/simplint/releases/tag/0.14.2).
This release starts larger files earlier during parallel checks and
sizes cache reads to the archive on disk.

Give bare `Final` annotations explicit types across virtualenv,
maintenance tasks and tests. The wheel installer also declares its lazy
`posixpath` import. Refresh the CodeQL mutant patches for the new
annotations.

The macOS GraalPy reseeding test timed out while uninstalling pip.
Collect each package directory once when cleaning up files from pip's
RECORD. The test also uses the existing fixture that keeps coverage out
of pip's subprocesses.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
gaborbernat added a commit to gaborbernat/virtualenv that referenced this pull request 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 deleted the fix/tcl-library-followup-174 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.

2 participants