fix(policy): avoid panic truncating multi-byte UTF-8 paths for display#2448
fix(policy): avoid panic truncating multi-byte UTF-8 paths for display#2448andrewwhitecdw wants to merge 1 commit into
Conversation
truncate_for_display sliced at a fixed byte index (&s[..77]), which panics when the index is not a char boundary. A policy with an over-long filesystem path containing multi-byte characters crashed the sandbox supervisor / OPA policy loader instead of producing the intended FieldTooLong violation. Back off to the nearest char boundary before slicing, and add regression tests. Signed-off-by: Andrew White <andrewh@cdw.com>
|
All contributors have signed the DCO ✍️ ✅ |
|
I have read the DCO document and I hereby sign the DCO. |
|
Label |
|
/ok to test 2da2947 |
johntmyers
left a comment
There was a problem hiding this comment.
gator-agent
PR Review Status
Validation: This is a valid, concentrated policy bug fix. It restores the intended FieldTooLong violation for overlong multi-byte filesystem paths instead of panicking. PR #2408 is the same author's vouch-closed predecessor, not an active competing implementation.
Head SHA: 2da2947774591e972811db09be1897a066c26169
Review findings:
- No blocking findings remain. The UTF-8 boundary search is bounded and preserves the existing display limit, and the regression test exercises the prior panic.
Docs: Not needed because this restores intended validation behavior without changing the policy schema, limits, commands, or documented workflow.
Testing: Applied test:e2e because the change affects policy enforcement, and posted /ok to test 2da2947774591e972811db09be1897a066c26169 to authorize the current head on NVIDIA runners.
Next state: gator:watch-pipeline
|
Label |
Summary
truncate_for_displayinopenshell-policysliced over-long strings at a fixed byte index (&s[..77]), panicking when the index lands inside a multi-byte UTF-8 character. A policy YAML with a filesystem path longer thanMAX_PATH_LENGTH(4096) containing multi-byte characters crashes the sandbox supervisor and OPA policy loader instead of producing the intendedFieldTooLongpolicy violation.This PR supersedes #2408, which was auto-closed by the vouch-check workflow before I was vouched.
Related Issue
N/A — small fix found during code review. Same bug class as #2446 (byte-index slicing on possibly multi-byte strings).
Changes
truncate_for_displaybacks off to the nearest char boundary before slicingTesting
mise run pre-commitpasses (mise unavailable in this environment; ran equivalentcargo fmt+cargo clippy -p openshell-policy --all-targets— clean)cargo test -p openshell-policy truncate_for_display— 2 passed)Checklist