edit_file diff rendering panics on invalid UTF-8 text

未关闭 适合新手
#4,955 0 条评论 0 个 reaction 已指派 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 重现 panic。为 wrapTokens 中的无效 UTF-8 添加回归测试。然后验证 diff 能在不发生 panic 的情况下渲染,并运行 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 分钟
30 天内合并 PR
221

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker/docker-agent 的其他 Issue

查看 docker/docker-agent 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。