You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
id(web): file-list tag pill truncation panics on a multi-byte character straddling byte 256 — templates.rs slices &v[..256] off-boundary #815
The web file list's tag-pill rendering truncates long tag values with a raw byte slice that panics when the cut point falls inside a multi-byte UTF-8 character — taking down the file-list request for any file carrying such a tag.
let truncated = if v.len() > crate::tags::TAG_DISPLAY_MAX_BYTES{// 256format!("{}…",&v[..crate::tags::TAG_DISPLAY_MAX_BYTES])}else{
v.clone()};
&v[..256] panics with byte index 256 is not a char boundary whenever byte 256 is mid-character. Tag values are user-controlled (set from the CLI, the bulk-tag UI, or synced from peers) and reach this code via get_file_list → FileInfo.tags (routes.rs), so one crafted/accidental tag value makes /files (and the /api/files partial) fail for that file list.
Repro (verified on main 1161bcff)
Verbatim harness of the two lines above with v = "a"×255 + "é" + "tail-tail-tail" (length 269 > 256; é occupies bytes 255..257):
thread 'main' panicked at trunc.rs:5:38:
end byte index 256 is not a char boundary; it is inside 'é' (bytes 255..257 of string)
Any value longer than 256 bytes whose byte-256 offset splits a 2–4-byte character triggers it (e.g. an emoji or CJK character at that offset, or a long CJK/accented value).
The safe helper already exists in the same crate
pkgs/id/src/commands/tag.rs:90-100 defines pub fn truncate_on_char_boundary(s: &str, max: usize) -> String, which walks back to a char boundary before slicing — and its tests already cover exactly this shape (tag.rs:407: a value with é straddling the limit). The web template re-implemented the truncation inline and missed the boundary walk.
Suggested fix
In templates.rs, replace the inline slice with the existing helper:
let truncated = crate::commands::tag::truncate_on_char_boundary(v,crate::tags::TAG_DISPLAY_MAX_BYTES);
(truncate_on_char_boundary returns the string unchanged when it fits, so the if can go.) Add a regression test rendering a file list whose tag value has a multi-byte character straddling byte 256, asserting the pill shows the boundary-truncated value + … and nothing panics.
Acceptance criteria
Rendering a file list containing a >256-byte tag value with a multi-byte character straddling byte 256 does not panic and shows the value truncated on a char boundary with ….
Values ≤256 bytes and pure-ASCII long values render exactly as before.
The web template uses the crate's existing truncate_on_char_boundary (no second inline implementation).
New regression test in the web templates tests; cargo test --features web web template tests pass.
Activity