Bound Slice and array length in idl codecs - #1624
Merged
Merged
Conversation
Contributor
✅ API Diff Results -
|
Unheilbar
marked this pull request as ready for review
September 2, 2026 15:41
product-security-plaid-production
Bot
requested review from
Krish-vemula and
vicentevieytes
September 2, 2026 15:42
dhaidashenko
previously approved these changes
Sep 2, 2026
silaslenihan
previously approved these changes
Sep 2, 2026
ilija42
previously approved these changes
Sep 2, 2026
amit-momin
reviewed
Sep 2, 2026
amit-momin
reviewed
Sep 2, 2026
Unheilbar
dismissed stale reviews from ilija42, silaslenihan, and dhaidashenko
via
September 2, 2026 17:35
7338293
amit-momin
reviewed
Sep 2, 2026
amit-momin
reviewed
Sep 2, 2026
amit-momin
approved these changes
Sep 2, 2026
Unheilbar
enabled auto-merge (squash)
September 3, 2026 14:21
|
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.




Description
The IDL codecs build every vec and bytes field as encodings.NewSlice(codec, builder.Int(4)). The upstream slice decoder reads that 4-byte count and passes it straight to reflect.MakeSlice, checking only that it is non-negative — so it allocates for the declared count before discovering the data isn't there. A few bytes of untrusted input allocate 2 GB for vec, up to 64 GB for vec.
Adds commoncodec.NewBoundedSlice, which wraps the length-prefix codec so a count whose implied footprint exceeds the 10 MiB Solana account limit is rejected while decoding the prefix, before MakeSlice runs. The bound uses the larger of the element's on-wire and in-memory size — a nested vec is 4 bytes on the wire but a 24-byte slice header in memory.
Wire format is unchanged and asserted byte-identical against the unbounded codec. The cap equals the whole account limit, so legitimate data — which must be smaller than its containing account or log — is never rejected.
Requires Dependencies
Resolves Dependencies