fix(policy): avoid panic truncating multi-byte UTF-8 paths for display#2408
Closed
andrewwhitecdw wants to merge 1 commit into
Closed
fix(policy): avoid panic truncating multi-byte UTF-8 paths for display#2408andrewwhitecdw wants to merge 1 commit into
andrewwhitecdw 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>
andrewwhitecdw
requested review from
a team,
derekwaynecarr,
maxamillion and
mrunalp
as code owners
July 22, 2026 04:09
|
Thank you for your interest in contributing to OpenShell, @andrewwhitecdw. This project uses a vouch system for first-time contributors. Before submitting a pull request, you need to be vouched by a maintainer. To get vouched:
See CONTRIBUTING.md for details. |
|
Thank you for your submission! We ask that you sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text: I have read the DCO document and I hereby sign the DCO. You can retrigger this bot by commenting recheck in this Pull Request. Posted by the DCO Assistant Lite bot. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Related Issue
N/A — small fix found during code review. Same bug class as #2406 (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