Skip to content

program: Improve account length validation#55

Merged
febo merged 2 commits into
mainfrom
febo/account-length
May 14, 2026
Merged

program: Improve account length validation#55
febo merged 2 commits into
mainfrom
febo/account-length

Conversation

@febo
Copy link
Copy Markdown
Contributor

@febo febo commented May 13, 2026

Problem

Currently account length validation is done implicitly when reading account data. It would be better to do it explicitly.

Solution

Replace all uses of from_bytes_unchecked for from_bytes.

@febo febo requested review from joncinque and lorisleiva May 13, 2026 17:10
@febo febo force-pushed the febo/account-length branch from 246976c to bb79735 Compare May 13, 2026 21:53
Copy link
Copy Markdown
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks great! Just one comment

Comment thread program/src/processor/set_immutable.rs Outdated
// SAFETY: There are no active borrows of the `metadata` account data and the
// account has been validated.
let header = unsafe { Header::from_bytes_mut_unchecked(metadata.borrow_unchecked_mut()) };
let header = Header::from_bytes_mut(metadata_account_data)?;
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.

Since validate_metadata is actually checking the len, it should be possible to keep using the unchecked version here, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! It also validates that the account is mutable. Code updated in b130a01

@febo febo requested a review from joncinque May 14, 2026 08:43
Copy link
Copy Markdown
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@febo febo merged commit fb104a2 into main May 14, 2026
9 checks passed
@febo febo deleted the febo/account-length branch May 14, 2026 12:26
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.

2 participants