stampchain-io / btc_stamps

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

An invalid JSON string caused a SyntaxError, resulting in the program terminating unexpectedly #379

Closed btcopenstamp closed 1 month ago

btcopenstamp commented 1 month ago

Describe the bug An invalid JSON string caused a SyntaxError, resulting in the program terminating unexpectedly. The issue first appeared on the testnet during the bitname testing process. The same code is used in src20, and when added to the src20 test cases for verification, it was found that this issue indeed causes the program to terminate unexpectedly.

Branch/Release/Commit Hash of Problem Branch dev.

To Reproduce Steps to reproduce the behavior:

  1. Using an invalid JSON string like this (such as extra quotes or missing quotes):
    {"p":"SRC-20","op":"DEPLOY","tick":"TEST","deci":8,"lim":1000000,"max":""1000000000"}

Expected behavior The program can continue running without terminating.

Screenshots

Traceback (most recent call last):
  File "/code/btc_stamps/indexer/test_src20.py", line 68, in test_src20_variations
    stamp_result, parsed_stamp, valid_stamp, prevalidated_src20 = parse_stamp(
  File "/code/btc_stamps/indexer/src/index_core/stamp.py", line 231, in parse_stamp
    return processor.process_stamp(stamp_data)
  File "/code/btc_stamps/indexer/src/index_core/stamp.py", line 31, in process_stamp
    stamp_data.process_and_store_stamp_data(
  File "/code/btc_stamps/indexer/src/index_core/models.py", line 559, in process_and_store_stamp_data
    stamp = convert_to_dict_or_string(self.data, output_format="dict")
  File "/code/btc_stamps/indexer/src/index_core/util.py", line 315, in convert_to_dict_or_string
    input_data = ast.literal_eval(input_data)
  File "/Users/mac/.pyenv/versions/3.10.13/lib/python3.10/ast.py", line 64, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
  File "/Users/mac/.pyenv/versions/3.10.13/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    {"p":"SRC-20","op":"DEPLOY","tick":"TEST","deci":8,"lim":1000000,"max":""1000000000"}
                                                                                       ^
SyntaxError: unterminated string literal (detected at line 1)

Additional context The location where the code execution failed: https://github.com/stampchain-io/btc_stamps/blob/b6164a4284da464f4c92d1c2ee9c99b3f3903705/indexer/src/index_core/util.py#L314-L317

Resolve the issue by catching the SyntaxError: https://github.com/stampchain-io/btc_stamps/blob/ebdb2965bf148877919ff0597492635e9e1c540a/indexer/src/index_core/util.py#L314-L317

reinamora137 commented 1 month ago

Can you also add this format into the test cases as well please.

btcopenstamp commented 1 month ago

Can you also add this format into the test cases as well please.

Sure, it’s added in https://github.com/stampchain-io/btc_stamps/pull/380/commits/d3b847bec6775b52c0df55b15f0d00474387b5f8.