Repository navigation
Description
OpenCodeReview Version
v1.13.3 (commit: 216dcf5, built: 2026-10-31T19:14:45Z)
Operating System
macOS (Apple Silicon)
Installation Method
Built from source
LLM Provider
Other OpenAI-compatible endpoint
Bug Description
The web viewer's truncate template function cuts strings on byte
boundaries. When a reviewed file's path contains multibyte characters
(CJK, Cyrillic, emoji, ...) and the 60-byte display limit lands inside
a rune, the rendered page contains invalid UTF-8 and browsers show the
corrupted rune as �.
The chain:
internal/viewer/server.go:478-483—truncateTextdoes
s[:n] + "…"(byte cut, not rune cut).internal/viewer/templates/session.html:98—
{{sessionTaskLabel .FilePath | truncate 60}}renders the truncated
file path in the session task table.sessionTaskLabel
(server.go:364) returns the path unchanged.html/templateescapes HTML but does not repair invalid UTF-8, so
the broken bytes reach the browser verbatim.
Why the test suite misses it: TestTruncateText in
internal/viewer/server_test.go:24 has the case
{"unicode truncated at byte boundary", 6, "你好世界", "你好…"}. With
3-byte CJK runes, n=6 is exactly a rune boundary (2 chars × 3 bytes),
so the case passes without ever cutting mid-rune — the test name
overstates what it covers.
Steps to Reproduce
- Review (or scan) a repo containing a file whose path has multibyte
characters, e.g. a change in
src/组件/用户资料/资料管理器.java(path longer than 60 bytes). - Run
ocr viewerand open the session's task table. - Observe the file-path cell rendering
�where the 60-byte cut
landed mid-rune.
Minimal unit-level reproduction against the real function:
truncateText(5, "你好世界") // "你好世界" is 12 bytes; n=5 splits 好
// -> "你\xe5\xa5…" (utf8.ValidString == false)Expected Behavior
Truncation happens on a rune boundary, so the viewer always emits
valid UTF-8. The project already has the rune-safe pattern in
internal/agent/util.go ([]rune(...)[:n]) and
internal/session/manifest.go:684.
Logs / Error Output
No CLI error output — the corruption is in the rendered HTML only.
Verified run against the real function and the real html/template renderer:
n=6 -> "你好…" valid=true (on-boundary; the only case the suite tests)
n=5 -> "你\xe5\xa5…" valid=false <- mid-rune cut, invalid UTF-8
html/template rendered: e4 bd a0 e5 a5 e2 80 a6 (valid=false; broken bytes reach the page)AI/LLM Disclosure
- I didn't use AI/LLM to assist or generate the content above.
Additional Context
- Scope: only the file-path truncation is vulnerable (
truncate 60in
session.html:98). The session-ID truncations (truncate 8/12) are
hex/ASCII and unaffected. - Severity: low, cosmetic — display-only corruption; no data or
security impact. The untruncatedtitleattribute still shows the
full path on hover. - Suggested fix: make
truncateTextrune-safe and add a true
mid-rune test case (e.g.{5, "你好世界", "你…"}), correcting the
misleading existing case name.
AI/LLM disclosure: this bug was found and this report drafted with
assistance from an AI coding assistant (OpenCode CLI, DeepSeek V4 Pro
model). Every claim above was verified by the reporter against the
source and with a local reproduction before submission.
Activity