Skip to content

Segfault when resetting the terminal after displaying an image #5649

Description

@pluiedev

Discussed in #3576

Originally posted by sergei-grechanik December 27, 2024
Ghostty sometimes crashes with a segmentation fault when the terminal is reset after displaying an image. To reproduce, run the following script sh ghostty_bug_placement_movecursor_direct.sh.txt:
ghostty_bug_placement_movecursor_direct.sh.txt

(Ubuntu 24.04, commit a8e5eef)

It crashes both in release and debug mode. Debug mode logs:
ghostty-image-then-reset-crash-log.txt


Maintainer's note: Reproducible on Linux (tip) with the following stack trace:

Stack trace
Segmentation fault at address 0xe8
debug(io_exec): termios change mode=pty.Mode{ .canonical = false, .echo = false }
/home/leah/coding/ghostty/src/terminal/PageList.zig:2447:21: 0x328efe5 in untrackPin (ghostty)
    assert(p != self.viewport_pin);
                    ^
/home/leah/coding/ghostty/src/terminal/kitty/graphics_storage.zig:632:47: 0x3437d2f in deinit (ghostty)
                .pin => |p| s.pages.untrackPin(p),
                                              ^
/home/leah/coding/ghostty/src/terminal/kitty/graphics_storage.zig:235:43: 0x341818e in delete (ghostty)
                    entry.value_ptr.deinit(&t.screen);
                                          ^
/home/leah/coding/ghostty/src/terminal/Screen.zig:282:29: 0x3383c2e in reset (ghostty)
    self.kitty_images.delete(
                            ^
/home/leah/coding/ghostty/src/terminal/Terminal.zig:2635:22: 0x3295938 in fullReset (ghostty)
    self.screen.reset();
                     ^
/home/leah/coding/ghostty/src/termio/stream_handler.zig:896:32: 0x368a001 in fullReset (ghostty)
        self.terminal.fullReset();
                               ^
/home/leah/coding/ghostty/src/terminal/stream.zig:1768:52: 0x368aa2d in escDispatch (ghostty)
                    0 => try self.handler.fullReset(),
                                                   ^
/home/leah/coding/ghostty/src/terminal/stream.zig:295:64: 0x369b74f in nextNonUtf8 (ghostty)
                    .esc_dispatch => |esc| try self.escDispatch(esc),
                                                               ^
/home/leah/coding/ghostty/src/terminal/stream.zig:155:37: 0x369ca03 in consumeUntilGround (ghostty)
                try self.nextNonUtf8(input[offset]);
                                    ^
/home/leah/coding/ghostty/src/terminal/stream.zig:143:54: 0x369cced in consumeAllEscapes (ghostty)
                offset += try self.consumeUntilGround(input[offset..]);
                                                     ^
/home/leah/coding/ghostty/src/terminal/stream.zig:99:49: 0x369d317 in nextSliceCapped (ghostty)
            offset += try self.consumeAllEscapes(input[offset..]);
                                                ^
/home/leah/coding/ghostty/src/terminal/stream.zig:74:41: 0x369de2f in nextSlice (ghostty)
                try self.nextSliceCapped(input[i .. i + len], &cp_buf);
                                        ^
/home/leah/coding/ghostty/src/termio/Termio.zig:604:39: 0x364a15f in processOutputLocked (ghostty)
        self.terminal_stream.nextSlice(buf) catch |err|
                                      ^
/home/leah/coding/ghostty/src/termio/Termio.zig:563:29: 0x360af5f in threadMainPosix (ghostty)
    self.processOutputLocked(buf);
                            ^
/nix/store/h6lccra69nr23676qq32h9qn1fba24v1-zig-0.13.0/lib/std/Thread.zig:408:13: 0x35b4423 in callFn__anon_143917 (ghostty)
            @call(.auto, f, args);
            ^
/nix/store/h6lccra69nr23676qq32h9qn1fba24v1-zig-0.13.0/lib/std/Thread.zig:674:30: 0x35258a2 in entryFn (ghostty)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x7fc5e0096a71 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7fc5e0096a71` was not available, trace may be incomplete

fish: Job 1, './zig-out/bin/ghostty' terminated by signal SIGABRT (Abort)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashCauses a crash, very high priority to fix

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions