zsh-workers
 help / color / mirror / code / Atom feed
* getjobtext() gives invalid utf8, leading to segfault
@ 2021-08-08 17:14 Carl Agrell
  2021-08-09  2:10 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Carl Agrell @ 2021-08-08 17:14 UTC (permalink / raw)
  To: zsh-workers

With the powerlevel10k prompt, running either of these two commands
causes the shell to segfault:
    $ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月光
    $ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月
The AAAs can be replaced with anything as long as the length is
unchanged (did not test with non-ascii though). Changing the kanji at
the end usually makes it not crash, strangely enough.

A minimal zshrc creating the same crash is
    _preexec() {
        [[ $2 == "" ]]
    }
    preexec_functions=(_preexec)

If we echo $2 instead of comparing it, it is printed as
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月�
hinting that it's a multibyte error. Curiously, /bin/echo instead
gives 月元 at the end.

Looking through the source, it looks like this string is created by
getjobtext(). This hints that similar errors might be seen in other
places where jobs are displayed, and indeed:
    $ cat /dev/stdin
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA月
    ^Z
    zsh: suspended  cat /dev/stdin
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA會

I am running `zsh 5.8 (x86_64-pc-linux-gnu)`, the one that is current
packaged in Arch Linux.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-09  5:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-08 17:14 getjobtext() gives invalid utf8, leading to segfault Carl Agrell
2021-08-09  2:10 ` Mikael Magnusson
2021-08-09  5:33   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).