Repository navigation
Fix StringM::from_str max length validation - #500
Merged
Merged
Conversation
leighmcculloch
marked this pull request as ready for review
February 26, 2026 03:12
leighmcculloch
enabled auto-merge
February 26, 2026 03:14
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a validation bug where StringM::from_str could construct values from unescaped bytes without enforcing the MAX length invariant, aligning its behavior with BytesM::from_str.
Changes:
- Update
StringM::from_strto route throughTryFrom<Vec<u8>>(b.try_into()) so max-length validation is enforced. - Apply the same fix to the generated
currandnextoutputs. - Add regression tests covering
StringM::from_strat/under/over the max length.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| xdr-generator/generator/header.rs | Fix generator template so StringM::from_str enforces MAX via TryFrom; includes formatting-only adjustments nearby. |
| src/curr/generated.rs | Regenerated curr output reflecting the StringM::from_str fix. |
| src/next/generated.rs | Regenerated next output reflecting the StringM::from_str fix. |
| tests/stringm.rs | New tests ensuring StringM::from_str rejects inputs exceeding MAX and accepts valid lengths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dmkozh
approved these changes
Feb 26, 2026
leighmcculloch
added a commit
that referenced
this pull request
Mar 4, 2026
* validate StringM max length in from_str * Update tests/stringm.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> (cherry picked from commit 1f84001)
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.
What
Validate the length of the bytes entering the
StringMwhen usingfrom_str.Why
StringM::from_strconstructed values directly from bytes without checking the length, so inputs longer thanMAXsucceeded silently instead of returningErr(Error::LengthExceedsMax). Routing throughTryFrom<Vec<u8>>enforces the invariant, matching the pattern already used byBytesM::from_str.Close #499