Skip to content

Fix StringM::from_str max length validation - #500

Merged
leighmcculloch merged 2 commits into
mainfrom
fix-stringm-from-str-max
Feb 26, 2026
Merged

leighmcculloch merged 2 commits into
mainfrom
fix-stringm-from-str-max

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Feb 26, 2026 •

Copy link
Copy Markdown
Member

What

Validate the length of the bytes entering the StringM when using from_str.

Why

StringM::from_str constructed values directly from bytes without checking the length, so inputs longer than MAX succeeded silently instead of returning Err(Error::LengthExceedsMax). Routing through TryFrom<Vec<u8>> enforces the invariant, matching the pattern already used by BytesM::from_str.

Close #499

@leighmcculloch
leighmcculloch requested a review from a team February 26, 2026 03:12
@leighmcculloch
leighmcculloch marked this pull request as ready for review February 26, 2026 03:12
Copilot AI review requested due to automatic review settings February 26, 2026 03:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_str to route through TryFrom<Vec<u8>> (b.try_into()) so max-length validation is enforced.
  • Apply the same fix to the generated curr and next outputs.
  • Add regression tests covering StringM::from_str at/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.

Comment thread tests/stringm.rs Resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@anupsdf
anupsdf requested a review from graydon February 26, 2026 17:53
@leighmcculloch
leighmcculloch added this pull request to the merge queue Feb 26, 2026
Merged via the queue into main with commit 1f84001 Feb 26, 2026
13 checks passed
@leighmcculloch
leighmcculloch deleted the fix-stringm-from-str-max branch February 26, 2026 18:50
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)
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.

Bug: StringM::from_str bypasses max length validation

3 participants