Return InvalidInstructionData for malformed token metadata instructions#1194
Open
bit2swaz wants to merge 2 commits into
Open
Return InvalidInstructionData for malformed token metadata instructions#1194bit2swaz wants to merge 2 commits into
bit2swaz wants to merge 2 commits into
Conversation
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.
Closes #1152
Summary
Malformed token metadata payloads for
Initialize,UpdateField, andRemoveKeycould reachTokenMetadataInstruction::unpack(input), trigger Borsh allocation on forged string lengths, and abort the program asProgramFailedToComplete. This adds a narrow pre-validation guard inprogram/src/processor.rsso recognized malformed payloads fail withInvalidInstructionDatainstead.What changed
program/src/processor.rsbeforeTokenMetadataInstruction::unpack(input).Initialize,UpdateField, andRemoveKey.ProgramError::InvalidInstructionDatafor malformed recognized payloads instead of falling through or panicking.Why
Before this change, malformed token metadata payloads for the affected variants could reach generic Borsh deserialization, attempt oversized allocation, and panic on SBF. In program-test this surfaced as
ProgramFailedToComplete.After this change, recognized malformed payloads are rejected locally and return
InstructionError(0, InvalidInstructionData).Scope
This change is intentionally narrow.
Initialize,UpdateField, andRemoveKeyare pre-validated.UpdateAuthority,Emit, and other metadata variants continue through the existingTokenMetadataInstruction::unpack(input)path unchanged.program/src/processor.rs, with targeted regression coverage in the three Rust legacy metadata test files.Tests
fail_initialize_with_forged_name_length_returns_invalid_instruction_data.fail_update_field_with_forged_value_length_returns_invalid_instruction_data.fail_remove_key_with_forged_key_length_returns_invalid_instruction_data.success_initializesuccess_updatesuccess_removeNotes
The Rust legacy integration tests load
target/deploy/spl_token_2022.sovia program-test, so rebuild the SBF artifact withmake build-sbf-programbefore runningmake test-clients-rust-legacy