SwiftTerm icon indicating copy to clipboard operation
SwiftTerm copied to clipboard

Crash on reverseIndex

Open migueldeicaza opened this issue 1 year ago • 0 comments

I caught the issue in the wild, the crash is:

    frame #3: 0x000000019475f134 libswiftCore.dylib`Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 652
    frame #4: 0x0000000102b7f84c LaTerminal`CircularList.shiftElements(start=47, count=3, offset=1, self=0x0000000280bf5680) at CircularList.swift:169:9
  * frame #5: 0x0000000102beebe4 LaTerminal`Terminal.reverseIndex(self=0x00000001043e4ed0) at Terminal.swift:4937:26
    frame #6: 0x0000000102bbeb98 LaTerminal`closure #84 in Terminal.configureParser(collect=0 values, flag=77, self=0x00000001043e4ed0) at Terminal.swift:868:76

The issue is that shiftElements is being called with start=47, but the buffer itself only has 42 lines. The 47 is a combination of buffer.y = 21 and buffer.base = 26. And also notice that buffer.y = buffer.scrollTop which is why this path is triggered at all, originMode=false, usingMargins() = false

I was running top, and messing up the display with debug output from a background process, and I had refreshed it a few times, and I had just attempted to go to the background with control-z

The data was: [0] = "\r" [1] = "\u{1b}" [2] = "[" [3] = "3" [4] = "4" [5] = "d" [6] = "\u{1b}" [7] = "[" [8] = "L" [9] = "\u{1b}" [10] = "[" [11] = "2" [12] = "2" [13] = ";" [14] = "2" [15] = "5" [16] = "r" [17] = "\u{1b}" [18] = "[" [19] = "2" [20] = "2" [21] = ";" [22] = "1" [23] = "H" [24] = "\u{1b}" [25] = "M" }

Cursor Vertical Absolute Position 34 Insert Line Set Top and Bottom Margin to 22;25 (sets buffer.scrollBottom = 24, buffer.scrollTop=21) Set Cursor Position 22;1 Reverse Index

Most likely, what we have here are two different buffers in action.

migueldeicaza avatar Sep 28 '22 21:09 migueldeicaza