[PR #1612] [MERGED] validate file part bounds to prevent panic #9991

Closed
opened 2026-02-16 18:14:31 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1612
Author: @omarshaarawi
Created: 8/4/2025
Status: Merged
Merged: 8/5/2025
Merged by: @adamdotdevin

Base: devHead: fix-file-part-bounds-panic


📝 Commits (1)

  • fe8996d validate file part bounds to prevent panic

📊 Changes

2 files changed (+15 additions, -5 deletions)

View changed files

📝 packages/tui/internal/components/chat/message.go (+12 -4)
📝 packages/tui/internal/components/chat/messages.go (+3 -1)

📄 Description

When the terminal is resized (in my case I was using Ghostty's split zoom), messages
containing file references would cause a panic:

Caught panic:

runtime error: slice bounds out of range [:91] with length 90

Restoring terminal...

goroutine 70 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:26 +0x64
github.com/charmbracelet/bubbletea/v2.(*Program).recoverFromPanic(0x1400015f200, {0x1057b9b20, 0x14004bce2b8})
        /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:1139 +0x10c
github.com/charmbracelet/bubbletea/v2.(*Program).handleCommands.func1.1.1()
        /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:479 +0x40
panic({0x1057b9b20?, 0x14004bce2b8?})
        /usr/local/go/src/runtime/panic.go:792 +0x124
github.com/sst/opencode/internal/components/chat.renderText(0x1400217e488, {0x105813e40, 0x1400061e540}, {0x1400235acbd, 0x5b}, {0x1400002826e, 0x8}, 0x1, 0x51, {0x140000344e0, ...}, ...)
        /Users/Shaarawi/git/opencode/packages/tui/internal/components/chat/message.go:231 +0x11f0
github.com/sst/opencode/internal/components/chat.(*messagesComponent).renderView.func2()
        /Users/Shaarawi/git/opencode/packages/tui/internal/components/chat/messages.go:347 +0x332c
github.com/charmbracelet/bubbletea/v2.(*Program).handleCommands.func1.1()
        /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:484 +0x64
created by github.com/charmbracelet/bubbletea/v2.(*Program).handleCommands.func1 in goroutine 86
        /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:474 +0x10c

File part positions reference positions in the original text, but when the terminal is resized, the text gets re-wrapped to fit the new width. The rendering code was using these original positions to slice the wrapped text without validating they were still within bounds. Now this only append file parts with valid bounds


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1612 **Author:** [@omarshaarawi](https://github.com/omarshaarawi) **Created:** 8/4/2025 **Status:** ✅ Merged **Merged:** 8/5/2025 **Merged by:** [@adamdotdevin](https://github.com/adamdotdevin) **Base:** `dev` ← **Head:** `fix-file-part-bounds-panic` --- ### 📝 Commits (1) - [`fe8996d`](https://github.com/anomalyco/opencode/commit/fe8996db51720e21da40049f9161706f65a8eed6) validate file part bounds to prevent panic ### 📊 Changes **2 files changed** (+15 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/tui/internal/components/chat/message.go` (+12 -4) 📝 `packages/tui/internal/components/chat/messages.go` (+3 -1) </details> ### 📄 Description When the terminal is resized (in my case I was using Ghostty's split zoom), messages containing file references would cause a panic: ```bash Caught panic: runtime error: slice bounds out of range [:91] with length 90 Restoring terminal... goroutine 70 [running]: runtime/debug.Stack() /usr/local/go/src/runtime/debug/stack.go:26 +0x64 github.com/charmbracelet/bubbletea/v2.(*Program).recoverFromPanic(0x1400015f200, {0x1057b9b20, 0x14004bce2b8}) /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:1139 +0x10c github.com/charmbracelet/bubbletea/v2.(*Program).handleCommands.func1.1.1() /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:479 +0x40 panic({0x1057b9b20?, 0x14004bce2b8?}) /usr/local/go/src/runtime/panic.go:792 +0x124 github.com/sst/opencode/internal/components/chat.renderText(0x1400217e488, {0x105813e40, 0x1400061e540}, {0x1400235acbd, 0x5b}, {0x1400002826e, 0x8}, 0x1, 0x51, {0x140000344e0, ...}, ...) /Users/Shaarawi/git/opencode/packages/tui/internal/components/chat/message.go:231 +0x11f0 github.com/sst/opencode/internal/components/chat.(*messagesComponent).renderView.func2() /Users/Shaarawi/git/opencode/packages/tui/internal/components/chat/messages.go:347 +0x332c github.com/charmbracelet/bubbletea/v2.(*Program).handleCommands.func1.1() /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:484 +0x64 created by github.com/charmbracelet/bubbletea/v2.(*Program).handleCommands.func1 in goroutine 86 /Users/Shaarawi/go/pkg/mod/github.com/charmbracelet/bubbletea/v2@v2.0.0-beta.4/tea.go:474 +0x10c ```` File part positions reference positions in the original text, but when the terminal is resized, the text gets re-wrapped to fit the new width. The rendering code was using these original positions to slice the wrapped text without validating they were still within bounds. Now this only append file parts with valid bounds --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:31 -05:00
yindo closed this issue 2026-02-16 18:14:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9991