Public bug reported: [Impact] In a UTF-8 locale, with a prompt containing \[...\] invisible sequences, widening the terminal so that a prompt which wrapped now fits on one line leaves the cursor short of the end of the prompt. The default colour prompt from /etc/skel/.bashrc qualifies on any *-256color terminal. The shortfall is one column per invisible byte on the prompt's old last screen line (5 for one trailing \e[00m). Typed text overwrites the prompt, and the error persists through further resizes and C-l until a new prompt is drawn.
Seen in practice by terminal applications whose panels change width, e.g. https://github.com/Bidthedog/throng/issues/584 and https://github.com/pingdotgg/t3code/issues/25419. The bug is in the bundled readline's _rl_redisplay_after_sigwinch(), which calls _rl_reset_prompt() only when the screen becomes narrower than the prompt. After a widen, the prompt's invisible-character table is therefore stale. Upstream fixed it in bash-5.3 patch 020: https://ftp.gnu.org/gnu/bash/bash-5.3-patches/bash53-020 The change is one line in lib/readline/display.c, plus patchlevel.h. Affected: 5.3-2ubuntu1 (resolute), 5.3-3ubuntu1 (stonking, tenacious). Debian 5.3-3 carries upstream patches up to 009 only. [Test Plan] 1. In a UTF-8 locale (LANG=C.UTF-8 or en_US.UTF-8), in a terminal 80 columns wide: d=/tmp/$(printf 'x%.0s' {1..100}); mkdir -p "$d"; cd "$d" bash --norc PS1='\[\e[01;34m\]\w\[\e[00m\]\$ ' Press RET; the prompt wraps onto a second line. 2. Widen the terminal to 150 columns. 3. Unpatched: the cursor sits 5 columns before the end of the prompt, and typing overwrites "\$ ". Patched: the cursor follows "\$ ". A scripted reproducer is attached. It drives bash through a pty and replays the output through the pyte terminal emulator; it fails before the patch and passes after. [Where problems could occur] _rl_reset_prompt() now runs on every SIGWINCH redisplay instead of only when the screen narrows. It re-runs readline's own prompt layout (line breaks and invisible-character counts) on each resize. Bash's PS1 expansion, including any command substitutions, is not re-run. Any regression would appear as prompt redraw problems after a resize. [Other Info] Verified in an ubuntu:26.04 container, three runs with identical results: - the installed package 5.3-2ubuntu1 is 5 columns short under C.UTF-8; - the same source rebuilt without changes is 5 columns short; - the same source with the bash53-020 display.c hunk applied is correct. In the C locale none of the three builds misplaces the cursor. ** Affects: bash (Ubuntu) Importance: Undecided Status: New ** Attachment added: "probe.py" https://bugs.launchpad.net/bugs/2173620/+attachment/6015742/+files/probe.py -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2173620 Title: Cursor misplaced after the terminal widens past a wrapped prompt (fixed upstream in bash53-020) To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/bash/+bug/2173620/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
