Skip to content

🐛 fix(bash): preserve prompts across locales - #3663

Merged
gaborbernat merged 5 commits into
pypa:mainfrom
gaborbernat:fix/bash-prompt-runtime
Nov 20, 2026
Merged

gaborbernat merged 5 commits into
pypa:mainfrom
gaborbernat:fix/bash-prompt-runtime

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Bash activation escaped the prompt one character at a time. A later GBK locale could absorb an escape when Bash drew PS1, allowing prompt text to run in the user's shell. The loop also made activation slow for long prompts (#3621). Bash now escapes the prompt in a single pass and keeps escape bytes separate from preceding multibyte text. This addresses draft advisory ANT-2026-CR2KPIYY.

Prompt redraw under a changed locale

Bash decodes prompt escapes and then expands the result when promptvars is enabled. The prior Bash branch escaped the two passes, following #3466, but an escape next to non-ASCII prompt text could be read as part of a multibyte character under GBK. The new branch inserts a nonprinting boundary before such an escape. It still escapes both passes when promptvars changes after activation or PS1 reaches a child shell.

Long prompt activation

The old loop copied the remaining prompt on each iteration. The new bytewise pass avoids that repeated copying. The Bash branch calls builtin printf, so a shell function cannot replace the prompt text. The Semgrep rule now checks the branch structure without requiring the removed loop.

Behavior changes

Bash keeps command substitution syntax in prompt values literal across the tested UTF-8, GBK, and GB18030 locale changes. Long prompts activate without the repeated-copy delay. The Bash branch now needs a working POSIX awk; it returns an error if that command fails. The zsh psvar branch remains as introduced for #3466. Source-time parsing of generated activation scripts under GB18030 is addressed separately in ANT-2026-UMMZJBBH.

Fixes #3621.

Reported by oss-scanner: ANT-2026-CR2KPIYY and ANT-2026-KNCFNMXA.

@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
@gaborbernat
gaborbernat force-pushed the fix/bash-prompt-runtime branch 4 times, most recently from 9758097 to 6a700b3 Compare November 20, 2026 09:10
The per-character Bash loop slowed activation as prompts grew and could
leave an escape byte inside a multibyte character after a locale change.
Escape bytes in one linear pass, with nonprinting boundaries where a
legacy decoder could absorb them. Keep both prompt expansion passes
escaped, including when promptvars changes after activation.

Fixes pypa#3621
The Bash version matrix runs on minimal images without the locale
utility. Ask the Python interpreter to validate each locale before
running its prompt case.
The prompt redraw expansion used by this locale test starts in Bash
4.4. The version matrix includes older Bash releases, which still run
the long-prompt activation case.
A shell function named printf can replace the prompt while the new
escape pass runs. Call Bash's builtin so activation keeps the supplied
prompt under that shell setup.
@gaborbernat
gaborbernat force-pushed the fix/bash-prompt-runtime branch from 6a700b3 to fd8c977 Compare November 20, 2026 10:44
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 11:37
@gaborbernat
gaborbernat merged commit 74b0632 into pypa:main Nov 20, 2026
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.

Bash activation slows with long prompts

1 participant