Skip to content

🐛 fix(xonsh): keep Tcl bytes in UTF-7 - #3709

Closed
gaborbernat wants to merge 27 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-tcl-utf7-174
Closed

gaborbernat wants to merge 27 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-tcl-utf7-174

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

PR #3660 kept non-ASCII Tcl library path bytes across locale changes in Xonsh, but its generated bytes literal could change when Xonsh read the script as UTF-7. The activator now writes those verified bytes as hexadecimal digits and reconstructs them when sourced. This completes the Xonsh path handling for draft advisory ANT-2026-174OWDGY.

Source decoding of embedded bytes

The previous repr(bytes) rendering left some original ASCII path text inside the generated Python literal. UTF-7 can interpret part of that text as encoded characters before Xonsh parses the literal, changing the path bytes that activation exports. The new rendering contains only hexadecimal digits for the original path bytes. Xonsh reconstructs them with the built-in bytes.fromhex and then decodes them with its active filesystem codec, preserving the exported bytes across source and filesystem encoding changes even if the shell has a variable named bytes.

flowchart LR
    B[Verified path bytes] --> O[Old bytes literal with path text]
    O --> U[UTF-7 source decode may change text]
    U --> D[Different exported bytes]
    B --> H[New hexadecimal digits]
    H --> R[Reconstruct bytes at source time]
    R --> S[Original exported bytes]
    classDef bad fill:#ffd6d6,stroke:#c1121f,color:#5c0000;
    classDef ok fill:#d8f3dc,stroke:#2d6a4f,color:#1b4332;
    class O,U,D bad;
    class H,R,S ok;
Loading

Behavior changes and checks

A benign Xonsh subprocess test now checks that a UTF-7 source session exports the original non-ASCII TCL_LIBRARY bytes. The UTF-7 case fails against current main and passes with this change; the existing UTF-8 source case and a session that shadows bytes also pass. The same renderer handles TK_LIBRARY. ASCII paths and Windows Unicode literals retain their previous behavior.

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

Replaces #3667 after its merge was reverted.

gaborbernat and others added 27 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 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/xonsh-tcl-utf7-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