Crash when starting emacsclient #1111

Closed
opened 4 months ago by gergelypolonkai · 9 comments

When i start emacsclient from foot, the terminal crashes. Here are the logs i could squeeze out of it. They are written when i start foot regardless of the crash.

info: main.c:421: version: 1.12.1 -pgo +ime +graphemes -assertions
info: main.c:428: arch: Linux x86_64/64-bit
info: main.c:440: locale: en_GB.UTF-8
info: config.c:2949: loading configuration from /home/polesz/.config/foot/foot.ini
info: fcft.c:338: fcft: 3.1.2 +graphemes +runs +svg(nanosvg) -assertions
info: fcft.c:377: fontconfig: 2.14.0, freetype: 2.12.1, harfbuzz: 4.0.0, utf8proc: 2.7.0 (Unicode 14.0.0)
info: fcft.c:839: /home/polesz/.fonts/Hack-Regular.ttf: size=8.00pt/8px, dpi=75.00
info: wayland.c:1286: DP-1: 1920x1080+0x1080@60Hz DELL U2414H 23.98" scale=1 PPI=96x98 (physical) PPI=96x98 (logical), DPI=91.88
info: wayland.c:1286: HDMI-A-1: 1920x1080+2350x0@60Hz 2D FHD LG TV 23.10" scale=1 PPI=96x98 (physical) PPI=96x98 (logical), DPI=95.37
info: wayland.c:1286: DVI-D-1: 1920x1080+1920x1080@60Hz HP V242h 23.98" scale=1 PPI=96x98 (physical) PPI=98x96 (logical), DPI=91.88
info: wayland.c:1439: requesting SSD decorations
info: fcft.c:839: /home/polesz/.fonts/Hack-BoldItalic.ttf: size=12.00pt/15px, dpi=91.88
info: fcft.c:839: /home/polesz/.fonts/Hack-Regular.ttf: size=12.00pt/15px, dpi=91.88
info: fcft.c:839: /home/polesz/.fonts/Hack-Italic.ttf: size=12.00pt/15px, dpi=91.88
info: fcft.c:839: /home/polesz/.fonts/Hack-Bold.ttf: size=12.00pt/15px, dpi=91.88
info: terminal.c:699: cell width=9, height=20
info: terminal.c:587: using 16 rendering threads
info: wayland.c:801: using SSD decorations

After this, just the SIGSEGV message comes when i start emacsclient.

Here’s the backtrace from gdb:

#0  render_cell.isra.0 (term=term@entry=0x5555555df3e0, pix=pix@entry=0x55555567b7e0,
    row=row@entry=0x5555556451a0, col=col@entry=104, row_no=row_no@entry=48,
    has_cursor=has_cursor@entry=false) at ../render.c:499
#1  0x000055555557b0bd in render_row (cursor_col=-1, row_no=48, row=0x5555556451a0,
    pix=0x55555567b7e0, term=0x5555555df3e0) at ../render.c:818
#2  render_worker_thread (_ctx=<optimized out>) at ../render.c:1690
#3  0x00007ffff7b71c99 in start_thread (arg=<optimized out>) at pthread_create.c:439
#4  0x00007ffff7bf7620 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

My config:

[main]
font = Hack:size=12

[scrollback]
lines = 10000

[cursor]
style = underline
blink = yes

[colors]
background = 000000
foreground = d3d7cf
regular0 = 000000
regular1 = cc0000
regular2 = 4e9a06
regular3 = c4a000
regular4 = 3465a4
regular5 = 75507b
regular6 = 06989a
regular7 = d3d7cf
bright0 = 555753
bright1 = ef2929
bright2 = 8ae234
bright3 = fce94f
bright4 = 729fcf
bright5 = ad7fa8
bright6 = 34e2e2
bright7 = eeeeec

[key-bindings]
spawn-terminal = Control+Shift+t

I start emacsclient with emacsclient -t -a '' file. Running a new non-windowed Emacs in the terminal doesn’t produce the error.

When i start emacsclient from foot, the terminal crashes. Here are the logs i could squeeze out of it. They are written when i start foot regardless of the crash. ``` info: main.c:421: version: 1.12.1 -pgo +ime +graphemes -assertions info: main.c:428: arch: Linux x86_64/64-bit info: main.c:440: locale: en_GB.UTF-8 info: config.c:2949: loading configuration from /home/polesz/.config/foot/foot.ini info: fcft.c:338: fcft: 3.1.2 +graphemes +runs +svg(nanosvg) -assertions info: fcft.c:377: fontconfig: 2.14.0, freetype: 2.12.1, harfbuzz: 4.0.0, utf8proc: 2.7.0 (Unicode 14.0.0) info: fcft.c:839: /home/polesz/.fonts/Hack-Regular.ttf: size=8.00pt/8px, dpi=75.00 info: wayland.c:1286: DP-1: 1920x1080+0x1080@60Hz DELL U2414H 23.98" scale=1 PPI=96x98 (physical) PPI=96x98 (logical), DPI=91.88 info: wayland.c:1286: HDMI-A-1: 1920x1080+2350x0@60Hz 2D FHD LG TV 23.10" scale=1 PPI=96x98 (physical) PPI=96x98 (logical), DPI=95.37 info: wayland.c:1286: DVI-D-1: 1920x1080+1920x1080@60Hz HP V242h 23.98" scale=1 PPI=96x98 (physical) PPI=98x96 (logical), DPI=91.88 info: wayland.c:1439: requesting SSD decorations info: fcft.c:839: /home/polesz/.fonts/Hack-BoldItalic.ttf: size=12.00pt/15px, dpi=91.88 info: fcft.c:839: /home/polesz/.fonts/Hack-Regular.ttf: size=12.00pt/15px, dpi=91.88 info: fcft.c:839: /home/polesz/.fonts/Hack-Italic.ttf: size=12.00pt/15px, dpi=91.88 info: fcft.c:839: /home/polesz/.fonts/Hack-Bold.ttf: size=12.00pt/15px, dpi=91.88 info: terminal.c:699: cell width=9, height=20 info: terminal.c:587: using 16 rendering threads info: wayland.c:801: using SSD decorations ``` After this, just the SIGSEGV message comes when i start emacsclient. Here’s the backtrace from gdb: ``` #0 render_cell.isra.0 (term=term@entry=0x5555555df3e0, pix=pix@entry=0x55555567b7e0, row=row@entry=0x5555556451a0, col=col@entry=104, row_no=row_no@entry=48, has_cursor=has_cursor@entry=false) at ../render.c:499 #1 0x000055555557b0bd in render_row (cursor_col=-1, row_no=48, row=0x5555556451a0, pix=0x55555567b7e0, term=0x5555555df3e0) at ../render.c:818 #2 render_worker_thread (_ctx=<optimized out>) at ../render.c:1690 #3 0x00007ffff7b71c99 in start_thread (arg=<optimized out>) at pthread_create.c:439 #4 0x00007ffff7bf7620 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 ``` My config: ``` [main] font = Hack:size=12 [scrollback] lines = 10000 [cursor] style = underline blink = yes [colors] background = 000000 foreground = d3d7cf regular0 = 000000 regular1 = cc0000 regular2 = 4e9a06 regular3 = c4a000 regular4 = 3465a4 regular5 = 75507b regular6 = 06989a regular7 = d3d7cf bright0 = 555753 bright1 = ef2929 bright2 = 8ae234 bright3 = fce94f bright4 = 729fcf bright5 = ad7fa8 bright6 = 34e2e2 bright7 = eeeeec [key-bindings] spawn-terminal = Control+Shift+t ``` I start emacsclient with emacsclient -t -a '' file. Running a new non-windowed Emacs in the terminal doesn’t produce the error.

This just occured to me, so i gave it a try. Setting TERM to xterm or xterm-256color prevents the crash.

This just occured to me, so i gave it a try. Setting `TERM` to `xterm` or `xterm-256color` prevents the crash.
dnkl added the
bug
label 4 months ago
Owner
#0  render_cell.isra.0 (term=term@entry=0x5555555df3e0, pix=pix@entry=0x55555567b7e0,
    row=row@entry=0x5555556451a0, col=col@entry=104, row_no=row_no@entry=48,
    has_cursor=has_cursor@entry=false) at ../render.c:499

In this frame, can you do p *cell?

Also, would you mind testing this on latest master?

> ``` > #0 render_cell.isra.0 (term=term@entry=0x5555555df3e0, pix=pix@entry=0x55555567b7e0, > row=row@entry=0x5555556451a0, col=col@entry=104, row_no=row_no@entry=48, > has_cursor=has_cursor@entry=false) at ../render.c:499 > ``` In this frame, can you do `p *cell`? Also, would you mind testing this on latest master?
Owner

From the looks of it, this crash can be triggered by emitting an invalid CSI 38;5;<idx>m sequence.

Foot doesn't validate the color index, and will use it as-is when looking up the color value in the 256-color table (when rendering a cell).

Thus, something like:

echo -e '\e[38;5;1024m TEST TEST \e[m'

should trigger a crash. Different values for "idx" (1024 in the example above) may be required to actually crash.

Which terminfo do you use by default? What's the output of infocmp -x for that terminfo?

From the looks of it, this crash can be triggered by emitting an invalid `CSI 38;5;<idx>m` sequence. Foot doesn't validate the color index, and will use it as-is when looking up the color value in the 256-color table (when rendering a cell). Thus, something like: ```sh echo -e '\e[38;5;1024m TEST TEST \e[m' ``` should trigger a crash. Different values for "idx" (1024 in the example above) may be required to actually crash. Which terminfo do you use by default? What's the output of `infocmp -x` for that terminfo?
Owner

It'd be great if you could first verify you're still seeing the crash on master, and then try #1113, which hopefully should fix the crash.

It'd be great if you could first verify you're still seeing the crash on master, and then try https://codeberg.org/dnkl/foot/pulls/1113, which hopefully should fix the crash.

I did try it on master, i just forgot to add it to the issue.

This magic ANSI sequence didn’t make it crash.

Here’s the p *cell output:

$1 = {wc = 32 U' ', attrs = {bold = false, dim = false, italic = false, underline = false, strikethrough = false, blink = false, conceal = false, reverse = false, fg = 16777215, clean = true, fg_src = COLOR_BASE256, bg_src = COLOR_BASE16, confined = true, selected = false, url = false, 

And last, but not least, #1113 indeed works, and emacsclient works just fine without $TERM magic ^_^

I did try it on master, i just forgot to add it to the issue. This magic ANSI sequence didn’t make it crash. Here’s the `p *cell` output: ``` $1 = {wc = 32 U' ', attrs = {bold = false, dim = false, italic = false, underline = false, strikethrough = false, blink = false, conceal = false, reverse = false, fg = 16777215, clean = true, fg_src = COLOR_BASE256, bg_src = COLOR_BASE16, confined = true, selected = false, url = false, ``` And last, but not least, #1113 indeed works, and emacsclient works just fine without $TERM magic ^_^

Oh, and i’m using the foot terminfo that got installed with Fedora’s foot package.

Oh, and i’m using the `foot` terminfo that got installed with Fedora’s foot package.

I think morning coffee arrived to my brain, so i could combine all the info you presented and i extracted from the crash to construct this echo command, that does crash foot:

echo -e '\e[38;5;16777215m TEST TEST \e[m'
I think morning coffee arrived to my brain, so i could combine all the info you presented and i extracted from the crash to construct this echo command, that *does* crash foot: ``` echo -e '\e[38;5;16777215m TEST TEST \e[m' ```
Owner

Great! Then we've taken care of foot's problem.

There's one remaining question though, and that's why Emacs emits the invalid CSI sequence. Which version of Emacs are you using?

I don't think there's anymore we can do in foot, and I believe there's an Emacs bug lurking here (or maybe an Emacs theme bug). But I'm afraid I don't know how to help. I use Emacs myself, but have never seen this issue before.

Anyway, I'll close this issue once the PR has been merged. But I encourage you to try to dig a little bit deeper on the Emacs side. Even if foot doesn't crash, you'll likely get wrong colors (at least for some of them).

Great! Then we've taken care of foot's problem. There's one remaining question though, and that's _why_ Emacs emits the invalid CSI sequence. Which version of Emacs are you using? I don't think there's anymore we can do in foot, and I believe there's an Emacs bug lurking here (or _maybe_ an Emacs theme bug). But I'm afraid I don't know how to help. I use Emacs myself, but have never seen this issue before. Anyway, I'll close this issue once the PR has been merged. But I encourage you to try to dig a little bit deeper on the Emacs side. Even if foot doesn't crash, you'll likely get wrong colors (at least for some of them).

I use Emacs 27.2, from the Fedora repos. I use the tango-dark theme which is, i believe, built-inʼ. I usually use it in graphics mode but sometimes i start a terminal based emacsclient, eg. for Git commit message editing.

Iʼll ask around, but yeah, this issue is definitely solved. Thanks for doing it so quick!

I use Emacs 27.2, from the Fedora repos. I use the tango-dark theme which is, i believe, built-inʼ. I usually use it in graphics mode but sometimes i start a terminal based emacsclient, eg. for Git commit message editing. Iʼll ask around, but yeah, this issue is definitely solved. Thanks for doing it so quick!
dnkl closed this issue 4 months ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: dnkl/foot#1111
Loading…
There is no content yet.