Skip to content

[js-legacy] Fix getExtensionTypes throwing on mints padded to Multisig::LEN - #1646

Closed
maxxexee wants to merge 1 commit into
solana-program:mainfrom
maxxexee:fix/js-legacy-tlv-padding
Closed

maxxexee wants to merge 1 commit into
solana-program:mainfrom
maxxexee:fix/js-legacy-tlv-padding

Conversation

@maxxexee

Copy link
Copy Markdown

Some valid Token-2022 mints make getExtensionTypes throw RangeError ERR_OUT_OF_RANGE. getAccountLenForMint throws too, since it calls through to it.

Two mints on mainnet are built this way today:

FmRC8giKx4nArGfwyo8wyjfZVmjPKnR51esKMayYTLm5
boomHNooN7sHVNMS3wJ33QmYBb3znTtgugRvDj39vsD

Why it happens: when an account's length would land exactly on Multisig::LEN, the program appends two zero bytes, an Uninitialized type with no length field. The Rust reader stops there (try_for_each_tlv_extension_type). The JS reader always reads a length after the type, so on those mints it reads past the end of the buffer.

What it costs: a wallet or tool that opens one of those mints and asks for its extensions crashes instead of showing the token. unpackMint itself works, the follow up call is what fails.

The change stops the loop when it sees Uninitialized, and only reads a type and length when both fit in the buffer. That is the same order the program's reader uses.

Testing:

  • new test in test/unit/extensionTypes.test.ts uses the real 191 byte layout: MetadataPointer, then TokenMetadata, then the 00 00 padding. It fails on main and passes with this change.
  • npm run test:unit: 111 passing
  • oxlint --max-warnings 0: clean
  • oxfmt --check: clean

Closes #1587

When an account length would equal Multisig::LEN, the program appends a
bare Uninitialized type with no length field. The Rust reader stops there,
but getExtensionTypes always read a length, so it read past the end of the
buffer and threw ERR_OUT_OF_RANGE on valid mints.

Stop on Uninitialized and guard the loop so both the type and length fit
before reading them. getAccountLenForMint goes through this function and is
fixed with it.
@maxxexee

Copy link
Copy Markdown
Author

Status check on this one.

It still applies to current main: getExtensionTypes reads a length for every entry unconditionally, so the padded Uninitialized entry is still read as a type followed by a garbage length. main has also moved 5 commits since this branch, so say the word and I will rebase.

One thing that may explain the silence: the workflow run for this branch is sitting at action_required, waiting for a maintainer to approve it, so CI has never actually executed against these changes. Approving the run would let the new unit test speak for itself.

@samkim-crypto

Copy link
Copy Markdown
Contributor

Thanks for looking into this! #1610 makes the same fix and was open first and it also covers overallocated data. I'm going to close this in favor of #1610. Sorry for the slow response.

@maxxexee

Copy link
Copy Markdown
Author

Thanks for looking into this! #1610 makes the same fix and was open first and it also covers overallocated data. I'm going to close this in favor of #1610. Sorry for the slow response.

Thanks for the update Sam! I'll keep poking around the codebase.

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.

js-legacy: getExtensionTypes throws on mints with Multisig::LEN padding

2 participants