js-algorand-sdk icon indicating copy to clipboard operation
js-algorand-sdk copied to clipboard

Decoding transaction with algosdk.decodeObj fails

Open hernandp opened this issue 4 years ago • 2 comments

Subject of the issue

Decoding transaction using algosdk.decodeObj will fail. The same procedure using msgpack-lite decode function will go thru without problems.

Your environment

Steps to reproduce

  1. Read the attached TXN file
  2. Decode using algosdk.decodeObj( ... )

Expected behaviour

As msgpack-lite decode function output:

 msgpack.decode(tx)
{
  fee: 1000,
  fv: 16011880,
  lv: 16012880,
  snd: <Buffer 9c ca 3c ee a0 28 af 2f a2 0a f4 01 1b da 0d 2c 37 0d 90 1d 40 c7 35 d0 79 c9 45 a3 3c 32 c1 ba>,
  type: 'appl',
  gen: 'mainnet-v1.0',
  gh: <Buffer c0 61 c4 d8 fc 1d bd de d2 d7 60 4b e4 56 8e 3f 6d 04 19 87 ac 37 bd e4 b6 20 b5 ab 39 24 8a df>,
  apid: 320310902,
  apaa: [
    <Buffer 69 41>,
    <Buffer 00 00 00 00 13 16 c4 98>,
    <Buffer 02 20 03 f6 9c de 98 01 00 02 26 01>,
    <Buffer ba 28 48 33 00 18 22 12 33 00 19 23 12 33 00 19 24 12 11 10 31 16 23 13 10 37 00 1c 01 31 00 12 10 31 20 32 03 12 10>
  ]
}

Actual behaviour

 algosdk.decodeObj(tx)
Uncaught RangeError: Extra 157 of 368 byte(s) found at buffer[211]
    at Decoder.createNoExtraBytesError (C:\src\multisig-dispatcher\node_modules\algo-msgpack-with-bigint\dist\Decoder.js:78:16)
    at Decoder.doDecodeSingleSync (C:\src\multisig-dispatcher\node_modules\algo-msgpack-with-bigint\dist\Decoder.js:88:24)
    at Decoder.decode (C:\src\multisig-dispatcher\node_modules\algo-msgpack-with-bigint\dist\Decoder.js:83:21)
    at Object.decode (C:\src\multisig-dispatcher\node_modules\algo-msgpack-with-bigint\dist\decode.js:13:20)
    at Object.decode (C:\src\multisig-dispatcher\node_modules\algosdk\dist\cjs\src\encoding\encoding.js:71:20)
    at Object.decodeObj (C:\src\multisig-dispatcher\node_modules\algosdk\dist\cjs\src\main.js:210:21)
>

hernandp avatar Sep 04 '21 02:09 hernandp

Test file:

init-app-mainnet.zip

hernandp avatar Sep 04 '21 02:09 hernandp

This RangeError means you have probably several msgpack object encoded in a single buffer. msgpack-lite is decoding the first one without alerting you there is more data to the buffer, the better behavior is to throw the error.

If your example errors at position 211 try slicing the buffer and decoding the following: tx.slice(0,211) and tx.slice(211).

We could add a method to decode multiple mspack objects to make this easier.

AlgoDoggo avatar May 01 '22 14:05 AlgoDoggo