Skip to content

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

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-tcl-utf7-174
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-tcl-utf7-174

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

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.

@gaborbernat gaborbernat added security Fixes a vulnerability or hardens the supply chain, CI or release bug labels Nov 20, 2026
@gaborbernat
gaborbernat force-pushed the fix/xonsh-tcl-utf7-174 branch from 66c4e53 to 3cfc691 Compare November 20, 2026 07:32
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 08:22
@gaborbernat
gaborbernat merged commit 91852b6 into pypa:main Nov 20, 2026
81 checks passed
@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.

1 participant