Skip to content

Fix size_of calculations for dynamically sized types in Lazy#4319

Open
jamie-osec wants to merge 3 commits intosolana-foundation:masterfrom
jamie-osec:lazy-miscalculated
Open

Fix size_of calculations for dynamically sized types in Lazy#4319
jamie-osec wants to merge 3 commits intosolana-foundation:masterfrom
jamie-osec:lazy-miscalculated

Conversation

@jamie-osec
Copy link
Collaborator

This PR addresses two issues with Lazy which resulted in miscalculations for dynamically sized types.

  • Enums: Enums are encoded with a tag byte before the payload. The size_of calculation for the inner data was passed the full data including the tag byte, instead of the actual inner payload, resulting in potential size miscalculations
  • Arrays: Previously, the size of the first element was calculated, then multiplied by the array length. This is incorrect, as an array of dynamically sized types (e.g. [String; 5]) have non-homogenous sizes. Correct this by calculating the size of each element

This can result in incorrect deserialisation, allowing malicious payloads to bypass security checks.

@vercel
Copy link

vercel bot commented Mar 17, 2026

@jamie-osec is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added lang fix Bug fix PR labels Mar 18, 2026
Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

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

The enum fix looks very elegant 👍

@swaroop-osec
Copy link
Collaborator

@jamie-osec Could you please update CHANGELOG as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix PR lang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants