Skip to content

program: Improve account length validation#55

Open
febo wants to merge 1 commit into
mainfrom
febo/account-length
Open

program: Improve account length validation#55
febo wants to merge 1 commit 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

// 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?

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