edit_file diff rendering panics on invalid UTF-8 text
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- testing-qa
Research direction
Start with pkg/tui/components/tool/editfile/render.go, especially wrapTokens around the reported line 520, and reproduce the panic with the described a\xff input. Add a regression test for invalid UTF-8 in wrapTokens, then verify that the diff renders without panicking and run the editfile package test.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Go
- Stars
- 4.7k
- Forks
- 565
- Avg merge
- 18h 52m
- Merged PRs (30d)
- 221
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from docker/docker-agent
-
A setting to turn off the models.dev catalog download (offline and strict-network use)Possibly taken @3431481073 claimed this 19 days ago. Openarea/config area/models
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
docker/docker-agent#4714 ·
Maintainers usually reply within 1 day
-
Error when trying to run sandbox example?Possibly taken @dgageot claimed this 27 days ago. Openarea/cli
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
docker/docker-agent#4672 · 1 comment · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
`edit_file` silently edits the first match when `oldText` occurs more than oncePossibly taken @dwin-gharibi claimed this 103 days ago. Openarea/tools
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docker/docker-agent#3929 · 2 comments ·
Maintainers usually reply within 1 day
-
area/api area/runtime
Difficulty 4/5 3-5 days Newbie friendliness 48/100
docker/docker-agent#4951 ·
Maintainers usually reply within 1 day
-
area/agent area/cli area/runtime
Difficulty 4/5 3-5 days Newbie friendliness 55/100
docker/docker-agent#4947 ·
Maintainers usually reply within 1 day
All issues in docker/docker-agent
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OneBusAway/maglev#2145 ·
Maintainers usually reply within 2 days
-
priority/medium status/ready type/chore
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
discobox-ai/discobox#1357 ·
Maintainers usually reply within 1 day
-
TestPseudoLocaleRemote fails now and then: it types the code before the laptop asks for itPossibly taken @fzn0x claimed this today. Openbug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
enhancement ui/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
jbigler/railswitch#243 ·
Maintainers usually reply within 1 day
-
Helm probes fail when DCGM Exporter requires TLS client certificatesPossibly taken @git-jxj claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NVIDIA/dcgm-exporter#775 ·
Maintainers usually reply within 1 day