edit_file diff rendering panics on invalid UTF-8 text
维护者通常 1 天内回复
评估
- 难度
- 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 内容生成。
描述
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
- Create a file whose content includes an invalid UTF-8 byte (e.g. a Latin-1
ésaved as0xE9, orprintf 'a\xff' > /tmp/x.txt). - Ask an agent to
edit_fileit. - 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
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/docker-agent 的其他 Issue
-
A setting to turn off the models.dev catalog download (offline and strict-network use)可能已有人在做 @3431481073 于 19 天前认领。 未关闭area/config area/models
难度 2/5 1-3 小时 新手友好度 72/100
docker/docker-agent#4714 ·
维护者通常 1 天内回复
-
Error when trying to run sandbox example?可能已有人在做 @dgageot 于 27 天前认领。 未关闭area/cli
难度 2/5 1-3 小时 新手友好度 62/100
docker/docker-agent#4672 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
`edit_file` silently edits the first match when `oldText` occurs more than once可能已有人在做 @dwin-gharibi 于 103 天前认领。 未关闭area/tools
难度 2/5 1-3 小时 新手友好度 78/100
docker/docker-agent#3929 · 2 条评论 ·
维护者通常 1 天内回复
-
area/api area/runtime
难度 4/5 3-5 天 新手友好度 48/100
docker/docker-agent#4951 ·
维护者通常 1 天内回复
-
area/agent area/cli area/runtime
难度 4/5 3-5 天 新手友好度 55/100
docker/docker-agent#4947 ·
维护者通常 1 天内回复
查看 docker/docker-agent 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
OneBusAway/maglev#2145 ·
维护者通常 2 天内回复
-
priority/medium status/ready type/chore
难度 2/5 1-3 小时 新手友好度 84/100
discobox-ai/discobox#1357 ·
维护者通常 1 天内回复
-
TestPseudoLocaleRemote fails now and then: it types the code before the laptop asks for it可能已有人在做 @fzn0x 今天认领。 未关闭bug priority: low
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
enhancement ui/ux
难度 2/5 1-3 小时 新手友好度 68/100
jbigler/railswitch#243 ·
维护者通常 1 天内回复
-
Helm probes fail when DCGM Exporter requires TLS client certificates可能已有人在做 @git-jxj 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
NVIDIA/dcgm-exporter#775 ·
维护者通常 1 天内回复