Skip to content

TUI panics in wrapping.rs:52 (byte index near u64::MAX) on bracketed-paste injection over stdin #20587

Closed

Description

@noeljackson

Description

Codex 0.125.0 panics in tui/src/wrapping.rs:52 when receiving certain bracketed-paste content over stdin via PTY.

Repro environment

  • codex-cli 0.125.0 (cw run invocation, but the panic also occurs over a plain pty injection)
  • TUI mode (codex "<initial prompt>", no exec)
  • Linux x86_64

Repro steps

  1. Launch codex in TUI mode under any pty wrapper that can inject stdin bytes after startup (e.g. cw run from codewire, or a Python pty.fork harness).
  2. After codex's TUI is initialized and ready for input, inject a bracketed-paste sequence followed by \r:
    \x1b[200~test message\x1b[201~\r
    
  3. Codex's TUI panics with:
    The application panicked (crashed).
    Message: byte index 18446603741554230913 is out of bounds of `<the pasted text>`
    Location: tui/src/wrapping.rs:52
    

The byte index is consistently near u64::MAX (around 1.84e19), strongly suggesting an unsigned integer underflow in the wrapping code.

Expected

Codex should accept the pasted content as one input event and either submit it (on the trailing \r) or buffer it for the user.

Observed

Panic at startup of input handling. Backtrace is reported as <empty> even with RUST_BACKTRACE=full.

Notes

  • The panic occurs even with very short ASCII-only bodies (e.g. "test message").
  • The panic is NOT triggered when the TUI is driven interactively via a real terminal emulator. It only fires when content arrives via stdin injection from a non-tty process.
  • Workaround: use codex app-server (JSON-RPC over stdio) instead of TUI for programmatic dispatch — the protocol exposes turn/steer for mid-flight input.

The location tui/src/wrapping.rs:52 is the obvious place to look — it's likely a slice operation &text[..pos] where pos was computed via subtraction that underflowed.

Activity

  1. added
    bug
    CLI
    TUI
    on May 1, 2026
  2. removed
    CLI
    on May 1, 2026
  3. misrtjakub commented on May 3, 2026

    @misrtjakub

    I put together a small patch for this path:

    https://github.com/openai/codex/compare/main...misrtjakub:fix/tui-wrap-borrowed-slice-range?expand=1

    The issue looks like the borrowed slice path can turn a negative pointer offset into a huge usize, then index text[end..] with that out-of-range byte index. The patch only trusts borrowed wrapped slices when their pointer range falls inside the original source text; otherwise it falls back to the existing owned-line mapper instead of panicking.

    Validation:

    env CODEX_SKIP_VENDORED_BWRAP=1 cargo test -p codex-tui borrowed_slice_range_rejects_slices_outside_source_text
    env CODEX_SKIP_VENDORED_BWRAP=1 cargo test -p codex-tui wrap_ranges
    cargo fmt --check
    

    I still cannot open an upstream PR because PR creation is currently limited to repository collaborators, but the compare branch is ready if this direction looks right.

  4. added a commit that references this issue on May 13, 2026
    5d7e6a2
  5. added a commit that references this issue on May 15, 2026
    5136d8d
  6. added a commit that references this issue on Jun 27, 2026
    6a354f3
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

    TUIbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions