Skip to content

Bound Slice and array length in idl codecs - #1624

Merged
Unheilbar merged 5 commits into
developfrom
add_bound_slice
Sep 3, 2026
Merged

Bound Slice and array length in idl codecs#1624
Unheilbar merged 5 commits into
developfrom
add_bound_slice

Conversation

@Unheilbar

@Unheilbar Unheilbar commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

✅ API Diff Results - github.com/smartcontractkit/chainlink-solana

✅ Compatible Changes (4)

pkg/solana/codec/common (4)
  • CheckElementCount — ➕ Added

  • MaxAccountBytes — ➕ Added

  • NewBoundedSize — ➕ Added

  • NewBoundedSlice — ➕ Added


📄 View full apidiff report

@Unheilbar
Unheilbar marked this pull request as ready for review September 2, 2026 15:41
@Unheilbar
Unheilbar requested review from a team as code owners September 2, 2026 15:41
dhaidashenko
dhaidashenko previously approved these changes Sep 2, 2026
silaslenihan
silaslenihan previously approved these changes Sep 2, 2026
ilija42
ilija42 previously approved these changes Sep 2, 2026
Comment thread pkg/solana/codec/common/bounded_size.go
Comment thread pkg/solana/codec/common/bounded_size.go
Comment thread pkg/solana/codec/common/bounded_size.go
Comment thread pkg/solana/codec/v2/solana.go Outdated
@Unheilbar
Unheilbar enabled auto-merge (squash) September 3, 2026 14:21
@cl-sonarqube-production

Copy link
Copy Markdown

@Unheilbar
Unheilbar merged commit ce5c403 into develop Sep 3, 2026
50 checks passed
@Unheilbar
Unheilbar deleted the add_bound_slice branch September 3, 2026 14:39
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.

5 participants