Repository navigation
fix(token): return an error from get_spl_account on short account data - #433
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Aursen
approved these changes
Oct 12, 2026
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.
What
litesvm_token::get_spl_accountslices the account data withdata[..T::LEN]before unpacking it, so it panics whenever the account exists but its data is shorter thanT::LEN. For example:get_spl_account::<Account>on a mint (82 bytes < 165) panics withrange end index 165 out of range for slice of length 82;get_spl_account::<Mint>on a wallet (0 bytes) panics the same way.Because
TransferChecked,MintToChecked,BurnCheckedandApproveCheckedread the mint throughget_spl_account, passing a wrong address as the mint makessend()panic instead of returningErr, even though the function already returnsResultand a missing account is reported asAccountNotFound.Fix
Take
data.get(..T::LEN)and fall back to the whole (shorter) data, soPack::unpacksees a slice of the wrong length and returnsInvalidAccountData, which is converted toFailedTransactionMetadatalike the other unpack errors. Accounts that are at leastT::LENlong (including Token-2022 accounts with extensions) are handled as before.Tests
Added
test_get_spl_account_with_short_datatocrates/token/tests/one_owner.rs: it checks thatget_spl_account::<Account>on a mint andget_spl_account::<Mint>on a wallet returnErr, and thatTransferChecked::send()with a wallet as the mint returnsErr. The test panics onmasterand passes with the fix;cargo test -p litesvm-token --test one_ownerpasses.This change was prepared with AI assistance (Claude) and reviewed before submission.
🤖 Generated with Claude Code