fix: UTF-8 safe string truncation in browser tool and debug logging - #398
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR introduces UTF-8 safe truncation mechanisms across the codebase to prevent panics when processing multibyte character sequences. Changes include replacing manual byte-slicing with a character-boundary-aware helper function, adding comprehensive unit tests for edge cases, and updating token output formatting in authentication status commands. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes unsafe byte-level string slicing that panics on multi-byte UTF-8 content (Cyrillic, CJK, emoji) in browser tool display truncation and OAuth token debug logging. Closes spacedriveapp#391
c902563 to
7751f6c
Compare
Summary
Fixes remaining unsafe byte-level string slicing (
&s[..N]) that panics when truncation lands inside a multi-byte UTF-8 character (Cyrillic, CJK, emoji).src/tools/browser.rs- 3 locations: DOM node name (200), input value (100), typed text display (50)src/main.rs- 2 locations: OAuth token debug logging (20)All switched to
floor_char_boundary(), matching the pattern already used across the rest of the codebase.Note: the
file_readtool mentioned in #391 is actually already safe - it uses line-based slicing andtruncate_at_char_boundary(). The real culprits were these browser/debug paths.Closes #391
Also fixes a pre-existing clippy collapsible_if lint in src/tools/send_message_to_another_channel.rs that was failing CI on main after the Signal adapter merge.
Test plan
cargo clippy --all-targets -- -D warningspasses cleancargo test --lib -- file— all 16 tests passNote
This fix eliminates 5 unsafe byte-slicing vulnerabilities across two files by replacing direct slice operations with UTF-8 boundary-aware truncation. Changes are limited to debug output formatting in OAuth logging and DOM snapshot rendering for the browser tool.
Written by Tembo for commit c902563. This will update automatically on new commits.