fix: Handle malformed array type definitions in IDL parser#4029
Open
AvhiMaz wants to merge 3 commits intosolana-foundation:masterfrom
Open
fix: Handle malformed array type definitions in IDL parser#4029AvhiMaz wants to merge 3 commits intosolana-foundation:masterfrom
AvhiMaz wants to merge 3 commits intosolana-foundation:masterfrom
Conversation
Replace unsafe .unwrap() calls in array_from_str with proper error handling
to prevent panics on malformed IDL array syntax.
Changes:
- Convert array_from_str return type from IdlType to Result<IdlType, Error>
- Replace rsplit_once(';').unwrap() with .ok_or_else() for missing semicolons
- Replace IdlType::from_str().unwrap() with .map_err() for invalid types
- Add input validation for empty strings and size limits
- Add validation for array element types and lengths
- Add validation for generic parameter names
- Include comprehensive test coverage for all error cases
Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>
|
@AvhiMaz is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
jamie-osec
reviewed
Oct 27, 2025
idl/spec/src/lib.rs
Outdated
| type Err = anyhow::Error; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| // Input validation |
Collaborator
There was a problem hiding this comment.
Please remove this and comments like it - this just adds noise to the code
jamie-osec
reviewed
Oct 27, 2025
idl/spec/src/lib.rs
Outdated
Comment on lines
+322
to
+324
| if s.len() > 1000 { | ||
| return Err(anyhow!("Type string too long (max 1000 chars)")); | ||
| } |
Collaborator
There was a problem hiding this comment.
We don't need to add arbitrary length bounds
jamie-osec
reviewed
Oct 27, 2025
idl/spec/src/lib.rs
Outdated
Comment on lines
+407
to
+415
| // Validate reasonable array size | ||
| if len == 0 { | ||
| return Err(anyhow!("Array length cannot be zero")); | ||
| } | ||
| if len > 1_000_000 { | ||
| return Err(anyhow!( | ||
| "Array length too large (max 1,000,000)" | ||
| )); | ||
| } |
Collaborator
There was a problem hiding this comment.
Please remove these checks, we shouldn't place arbitrary limits
jamie-osec
reviewed
Oct 27, 2025
idl/spec/src/lib.rs
Outdated
| ) | ||
| } | ||
|
|
||
| // Tests for the vulnerability fix - missing semicolon |
Collaborator
There was a problem hiding this comment.
These are not vulnerabilities, and these comments are not necessary and add noise.
Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>
e6c38b4 to
5a2a398
Compare
Author
|
@jamie-osec all test cases have passed, could you please merge it? |
0x4ka5h
approved these changes
Dec 3, 2025
This was referenced Mar 13, 2026
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.
Fixes #4016
Replace unsafe .unwrap() calls in array_from_str with proper error handling
to prevent panics on malformed IDL array syntax.
Changes: