Skip to content

program: Return an error instead of panicking on Reallocate overflow - #381

Merged
joncinque merged 1 commit into
solana-program:mainfrom
ara-stock:program-reallocate-overflow
Oct 12, 2026
Merged

joncinque merged 1 commit into
solana-program:mainfrom
ara-stock:program-reallocate-overflow

Conversation

@ara-stock

Copy link
Copy Markdown
Contributor

Problem

Reallocate computes the new account length with size_of::<RecordData>().checked_add(data_length).unwrap(). A data_length close to u64::MAX overflows the addition, and the program panics (SBF program Panicked in program/src/processor.rs at 164:18) instead of returning an error. A data_length that does not fit in usize already returns InvalidArgument.

Summary of Changes

  • Return ProgramError::InvalidArgument when the length addition overflows, so it matches the existing usize::try_from error.
  • Add a functional test that sends Reallocate with u64::MAX and expects InvalidArgument. Before the change it fails with ProgramFailedToComplete.

I used an AI assistant (Claude) while preparing this. I reproduced the issue and checked the fix and tests myself.

🤖 Generated with Claude Code

Reallocate added the record header size to the requested data length
with checked_add(...).unwrap(), so a data_length close to u64::MAX made
the program panic instead of returning InvalidArgument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@joncinque joncinque left a comment

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.

Thanks

@joncinque
joncinque merged commit 6a52a5e into solana-program:main Oct 12, 2026
23 checks passed
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