edit_file diff rendering panics on invalid UTF-8 text

オープン 初心者向け
#4,955 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@TDnorthgarden がすでに取り組んでいます。

2026年11月18日 から。

  • #4956 @TDnorthgarden による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
testing-qa

調査の方向性

pkg/tui/components/tool/editfile/render.goから始め、特に報告された520行目付近のwrapTokensを確認し、説明されている入力a\xffでパニックを再現してください。wrapTokensで無効なUTF-8を扱う回帰テストを追加してください。次に、パニックを起こさずにdiffが描画されることを確認し、editfileパッケージのテストを実行してください。

索引モデルが issue の本文から書いたものです。

説明

area/tui
Description

The edit-diff / confirmation-preview renderer crashes the whole TUI when the edited file contains invalid UTF-8 bytes (Latin-1 sources, GBK comments, binary-ish files).

wrapTokens (pkg/tui/components/tool/editfile/render.go:495-525) wraps syntax-highlighted tokens to a width. It accumulates the taken bytes with utf8.RuneLen(r) while iterating for _, r := range text — range decodes an invalid byte as U+FFFD consuming one source byte, but utf8.RuneLen(U+FFFD) is 3, so fitLen overcounts and text[:fitLen] slices past the string (:520).

Verified minimal repro (a file containing the bytes a\xff), from a unit test against the real package:

$ go test ./pkg/tui/components/tool/editfile -run TestWrapTokensInvalidUTF8
panic: runtime error: slice bounds out of range [:4] with length 2
...editfile.wrapTokens(...) render.go:520

Reachability: handleEditFile has no binary-content guard before persisting the result meta, and the in-process EditFileMeta reaches the renderer without a JSON roundtrip that would sanitize invalid bytes, so any edit_file on such a file panics the bubbletea View and kills the process.

Expected Behavior

Rendering an edit diff never panics; invalid bytes render safely (highlighted or replaced).

Actual Behavior

The process panics with slice bounds out of range mid-render.

Steps to Reproduce
  1. Create a file whose content includes an invalid UTF-8 byte (e.g. a Latin-1 é saved as 0xE9, or printf 'a\xff' > /tmp/x.txt).
  2. Ask an agent to edit_file it.
  3. The confirmation/diff view panics.
Docker Agent version

No response

OS & terminal

No response

Model used

No response

Error output

Screenshots

No response

Additional context

Fix: take the byte length from the range position (for i, r := range text with the rune's encoded size) or decode with utf8.DecodeRuneInString; add a wrapTokens test with invalid UTF-8. Verified on main @ 19a735644. Happy to submit the fix.

主要言語
Go
スター
4.7k
フォーク
565
平均マージ
18時間 52分
マージ済み PR(30日)
221

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/docker-agent のほかの issue

docker/docker-agent の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。