Skip to content

Fix #1721: char-safe truncation in sanitize_system_prompt#882

Open
AlexMikhalev wants to merge 23 commits into
mainfrom
pr/1721-utf8-boundary-panic
Open

Fix #1721: char-safe truncation in sanitize_system_prompt#882
AlexMikhalev wants to merge 23 commits into
mainfrom
pr/1721-utf8-boundary-panic

Conversation

@AlexMikhalev
Copy link
Copy Markdown
Contributor

Summary

Security fix for UTF-8 boundary panic in sanitize_system_prompt.

Changes

  • fix(security): char-safe truncation in sanitize_system_prompt (Fixes #1721)

Root Cause

The sanitize_system_prompt function was using byte-indexed truncation which could cause UTF-8 multibyte characters to be split, potentially exposing internal state or causing panics.

Fix

Replace byte-indexed truncation with char-safe truncation that properly handles multibyte UTF-8 characters.

Related

  • Issue: #1721
  • Release: v2026.05.19

forge-admin and others added 23 commits May 19, 2026 11:30
…1721

Replace byte-slice truncation prompt[..MAX_PROMPT_LENGTH] with
prompt.chars().take(MAX_PROMPT_LENGTH).collect() to prevent panic
when MAX_PROMPT_LENGTH falls inside a multi-byte UTF-8 character.

Adds test_sanitize_multibyte_boundary to verify correct behaviour.
- Redirect all command output through tee to build-output.log
- ADF agent runner truncates stderr at ~8KB, hiding clippy/build/test results
- Fix parse_build_md: was concatenating lines without newlines
- BUILD_LOG set to $ADF_WORKING_DIR/build-output.log per run

Refs #1721
- Add project.rs with discover() function that walks up from cwd to find .terraphim/
- Change global_shortcut from String to Option<String> in Config
- Add merge_with() and with_project() methods to ConfigBuilder
- Update TuiService::new to accept no_project_config parameter
- Add merge_project_config() helper that discovers and merges project config
- Update all call sites and tests to use new signatures

Refs #1674
- Add project.rs with discover() function that walks up from cwd to find .terraphim/
- Change global_shortcut from String to Option<String> in Config
- Add merge_with() and with_project() methods to ConfigBuilder
- Update TuiService::new to accept no_project_config parameter
- Add merge_project_config() helper that discovers and merges project config
- Update all call sites and tests to use new signatures

Refs #1674
- cargo clippy -D warnings caught &real.join() where real.join() works
- Affects create_dir_all and canonicalize calls in test

Refs #1721
# Conflicts:
#	crates/terraphim_config/src/project.rs
- Add project-level config discovery section to terraphim_config summary
- Update main summary.md with new ProjectConfig type and discovery feature
- Add release announcement to .docs/releases/v2026.05.19.md

Refs: project config discovery feature (commits 59cd233, 26f5b87)
…ld-runner fixes

- Replace byte-indexed prompt truncation with .chars().take() to prevent
  UTF-8 byte-boundary panic in sanitize_system_prompt (Fixes #1721)
- Add test_sanitize_multibyte_boundary test for char-safe truncation
- Implement project-level config discovery for .terraphim/ directories
- Fix build-runner-llm.sh: pipefail for correct exit codes,
  tee output to build-output.log (ADF truncates stderr),
  fix parse_build_md command extraction
- Fix clippy warnings: needless_borrows_for_generic_args in project.rs,
  unnecessary_cast in llm_bridge.rs, field-reassign-with-default in config
- Revert incorrect TuiService::new(None, false) to TuiService::new(None)
- Fix global_shortcut Option<String> consistency across test files
- Mark LLM bridge integration tests as #[ignore] (require live client)

Refs #1721
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant