You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
js-legacy: Fix variable-size encoding of COptionPubkey (#71)
#### Problem
The JS library encodes and decodes `COption<Pubkey>` improperly. During
encoding, it overallocates the instruction data buffer to always include
the additional 32 bytes, even when the value is `null`. During decoding,
it assumes the worst-case size for the instruction data length.
#### Summary of changes
buffer-layout actually contains the way to do this right, by properly
implementing `getSpan` to return an error if it's ever used without a
buffer:
https://github.com/solana-labs/buffer-layout/blob/ee6cdb8074265b04c884485bb46738cdbc077e41/src/Layout.ts#L282
So this properly fixes the encoding and decoding at the same time:
* during encoding, overallocate to the worst case, then truncate down
* correctly return an error during `getSpan`
* during decoding, use the input buffer with `getSpan` to dynamically
calculate the expected length
* test the behavior for transfer fee encoding / decoding
0 commit comments