MultiChain / multichain-explorer

Web-based explorer for MultiChain blockchains
GNU Affero General Public License v3.0
177 stars 140 forks source link

Dangerous use of .index in Parse Functions (Error on parse_new_issuance_metadata_10007) #46

Open tloriato opened 5 years ago

tloriato commented 5 years ago
Traceback (most recent call last):
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 3115, in catch_up
explorernode_1  |     if not store.catch_up_rpc(dircfg):
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 3711, in catch_up_rpc
explorernode_1  |     store.import_block(block, chain = chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 1404, in import_block
explorernode_1  |     tx['tx_id'] = store.import_and_commit_tx(tx, pos == 0, chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 2437, in import_and_commit_tx
explorernode_1  |     tx_id = store.import_tx(tx, is_coinbase, chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 2288, in import_tx
explorernode_1  |     opdrop_type, val = util.parse_op_drop_data(data, chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/util.py", line 426, in parse_op_drop_data
explorernode_1  |     return func(data)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/util.py", line 439, in parse_op_drop_data_10007
explorernode_1  |     retval = parse_new_issuance_metadata_10007(data[5:])
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/util.py", line 753, in parse_new_issuance_metadata_10007
explorernode_1  |     fname = searchdata[:searchdata.index("\0")]
explorernode_1  | ValueError: substring not found

string.index throws an error when it doesn't encounter the specified substring, which is a dangerous behavior. I've been trying to fix this, but I don't completely understand the function yet.

At the time of error:

>print(searchdata)
> nd,receive}
tloriato commented 5 years ago

Managed to reproduce it and create the smallest possible example. It fails when the "details" object field in "issue(From)" is:

{
      "key1": "medium size string value just to fill space",
      "key2": "medium size string value just to fill space",
      "key3": "medium size string value just to fill space",
      "key4": "medium size string value just to fill space",
      "key5": "medium size string value just to fill space"
}

ps: the assetname has 32 characters

Remove "key5" and it works, insert it and it doesn't. I believe it's something related to total size? Very strange for python.

Node.js script if you would like to test (https://gist.github.com/tloriato/5f0fbb42426aae28850d94dd72d8c612)

tloriato commented 5 years ago

Another error in the same function:

explorernode_1  | Traceback (most recent call last):
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 3157, in catch_up
explorernode_1  |     store.catch_up_dir(dircfg)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 3819, in catch_up_dir
explorernode_1  |     store.import_blkdat(dircfg, ds, blkfile['name'])
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 3957, in import_blkdat
explorernode_1  |     store.import_block(b, chain = chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 1442, in import_block
explorernode_1  |     tx['tx_id'] = store.import_and_commit_tx(tx, pos == 0, chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 2475, in import_and_commit_tx
explorernode_1  |     tx_id = store.import_tx(tx, is_coinbase, chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/DataStore.py", line 2326, in import_tx
explorernode_1  |     opdrop_type, val = util.parse_op_drop_data(data, chain)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/util.py", line 426, in parse_op_drop_data
explorernode_1  |     return func(data)
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/util.py", line 439, in parse_op_drop_data_10007
explorernode_1  |     retval = parse_new_issuance_metadata_10007(data[5:])
explorernode_1  |   File "/root/.local/lib/python2.7/site-packages/Mce/util.py", line 728, in parse_new_issuance_metadata_10007
explorernode_1  |     if k in json_data:
explorernode_1  | TypeError: argument of type 'long' is not iterable

I believe he's trying to converted a string like "65496845000165" to long? That's the only "long" amount in my payload.