stampchain-io / btc_stamps

Bitcoin Stamps Indexer
https://stampchain.io
GNU Affero General Public License v3.0
14 stars 5 forks source link

Branch `bitname/testnet` An invalid `tokenid` with base64/unicode string caused a UnicodeDecodeError, resulting in the program terminating unexpectedly #384

Closed btcopenstamp closed 1 month ago

btcopenstamp commented 3 months ago

Describe the bug An invalid tokenid with base64/unicode string caused a UnicodeDecodeError, resulting in the program terminating unexpectedly.

Branch/Release/Commit Hash of Problem Branch bitname/testnet.

To Reproduce Steps to reproduce the behavior:

  1. Using an invalid base64/unicode tokenid such as 0918 etc.

Expected behavior The program can continue running without terminating.

Screenshots

Unhandled Exception
Traceback (most recent call last):
  File "/usr/src/app/start.py", line 19, in <module>
    main()
  File "/usr/src/app/start.py", line 15, in main
    server.start_all(db)
  File "/usr/src/app/src/index_core/server.py", line 359, in start_all
    blocks.follow(db)
  File "/usr/src/app/src/index_core/blocks.py", line 934, in follow
    block_processor.process_transaction_results(tx_results)
  File "/usr/src/app/src/index_core/blocks.py", line 127, in process_transaction_results
    _, src101_dict = parse_src101(self.db, prevalidated_src, self.processed_src101_in_block)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/src/index_core/src101.py", line 598, in parse_src101
    processor.process()
  File "/usr/src/app/src/index_core/src101.py", line 584, in process
    self.src101_dict = validator.process_values()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/src/index_core/src101.py", line 64, in process_values
    self._process_tokenid_value(key, value)
  File "/usr/src/app/src/index_core/src101.py", line 181, in _process_tokenid_value
    self.src101_dict[key + "_utf8"] = base64.b64decode(value).decode("utf8").lower()
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 0: invalid continuation byte

Additional context The location where the code execution failed: https://github.com/stampchain-io/btc_stamps/blob/d476792058ac481993196670a2ef94a622a7d21f/indexer/src/index_core/src101.py#L181