Skip to content

Fixed: Fix session cleanup, terminal emulator resize, OSC 104, DECCARA, ESC F, tokenizer and shebang bugs - #5247

Open
BuildWithAni wants to merge 4 commits into
termux:masterfrom
BuildWithAni:fix/termux-session-resize-tokenizer-emulator-fixes
Open

Fixed: Fix session cleanup, terminal emulator resize, OSC 104, DECCARA, ESC F, tokenizer and shebang bugs#5247
BuildWithAni wants to merge 4 commits into
termux:masterfrom
BuildWithAni:fix/termux-session-resize-tokenizer-emulator-fixes

Conversation

@BuildWithAni

Copy link
Copy Markdown

Fixes several bugs found while reviewing the codebase, across app, terminal-emulator and termux-shared modules.

  1. Finished sessions never removed when activity is not bound (TermuxTerminalSessionServiceClient.java). onSessionFinished() was left empty, so sessions that finished while the activity was not bound were never removed, their results never sent and their notifications never updated. Now it mirrors TermuxTerminalSessionActivityClient.onSessionFinished() minus the UI side effects. Also removed the full-screen work-around OnTouchListener leak by removing it in TermuxActivity.onDestroy() and deduplicating listener creation in FullScreenWorkAround.java.

  2. TerminalBuffer.resize() crash on unpaired high surrogate (TerminalBuffer.java). When resizing, an unpaired high surrogate at the end of lastNonSpaceIndex caused String.codePointAt() to throw IndexOutOfBoundsException. The surrogate is now replaced with UNICODE_REPLACEMENT_CHAR before copying. Also removed the stale "NEWLY INTRODUCED BUG" comment.

  3. OSC 104 color index out of bounds (TerminalEmulator.java). indexOf outside 0..NUM_INDEXED_COLORS-1 (259) caused ArrayIndexOutOfBoundsException when resetting color index palette entries. The range is now bounds-checked and the loop restructured.

  4. DECCARA/DECRARA coordinates not clamped to effective margins (TerminalEmulator.java). Parameters are 1-based and top/left are inclusive while bottom/right are exclusive; the effective margins under origin mode were not respected, so rectangles could extend into the wrong region. Coordinates are now clamped to the effective margins.

  5. ESC F moved cursor to wrong position (TerminalEmulator.java). It moved to the top row but not the bottom-left corner of the screen. Now moves to (mBottomMargin - 1, ...) with origin-mode column handling.

  6. ArgumentTokenizer crash on trailing backslash (ArgumentTokenizer.java). A trailing \ threw StringIndexOutOfBoundsException; it is now kept as a literal.

  7. Shebang interpreter arguments dropped (TermuxShellUtils.java). setupShellCommandArguments() now preserves #!/bin/bash -e (keeps -e) and #!/usr/bin/env bash (passes bash as the executable) so the interpreter is executed correctly.

All modules compile successfully:

BUILD SUCCESSFUL

Unit tests for terminal-emulator and app pass:

BUILD SUCCESSFUL

…ux-shared

- Fixed: Send SIGKILL to process in AppShell.killIfExecuting() unconditionally since setStateFailed() sets state to FAILED and isExecuting() will always be false after that, so SIGKILL was never sent
- Fixed: Return early in AmSocketServer.processAmClient() after sending error result to client so that a bogus success result frame is not sent afterwards
- Fixed: Use client socket fd instead of server socket fd in LocalClientSocket.available() to check for available data
… bound

- Fixed: Implement onSessionFinished() in TermuxTerminalSessionServiceClient to remove finished sessions when the TermuxActivity is not bound to the TermuxService, since TermuxTerminalSessionActivityClient was the only client that processed finished sessions. Sessions that finished while the activity was unbound were never removed, plugin results were never sent back and the notification was never updated, so the service would not stop
- Fixed: Remove the global layout listener of FullScreenWorkAround when activity is destroyed and deduplicate instances on re-apply so that the listener does not keep running and hold activity references after the activity has been destroyed
- Fixed: Remove stale resize style indexing bug comment and guard against unpaired high surrogate at end of row in TerminalBuffer.resize() so that rows ending with an unpaired high surrogate do not read mText out of bounds
- Fixed: Validate OSC 104 color index before resetting it and restructure the parameter loop so that malformed input does not crash with ArrayIndexOutOfBoundsException or StringIndexOutOfBoundsException
- Fixed: Clamp DECCARA and DECRARA rectangle coordinates to effective margins so that bottom and right bounds never exceed the screen dimensions and the last row and column are not excluded
- Fixed: Move cursor to lower-left corner of screen instead of top row in ESC F handler
…shebang interpreter arguments

- Fixed: Guard against reading past the end of the string in ArgumentTokenizer when a double quoted argument ends with a backslash so that a StringIndexOutOfBoundsException is not thrown
- Fixed: Preserve shebang interpreter arguments like the -e flag of #!/bin/bash -e and the interpreter name of #!/usr/bin/env bash in TermuxShellUtils.setupShellCommandArguments() instead of dropping everything after the first whitespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant