mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#25367: [contrib] message-capture-parser: fix out of bounds error for empty vectors
42bbbba7c8
message-capture-parser: fix out of bounds error for empty vectors (Sebastian Falbesoner) Pull request description: The script [message-capture-parser.py](https://github.com/bitcoin/bitcoin/blob/master/contrib/message-capture/message-capture-parser.py) currently throws an "out of bounds" error if a message containing an empty integer vector element is tried to converted to JSON (e.g. by the BIP157 message `cfcheckpt` with empty `FilterHeaders` vector): ``` Traceback (most recent call last): File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 217, in <module> main() File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 202, in main process_file(str(capture), messages, "recv" in capture.stem, progress_bar) File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 162, in process_file msg_dict["body"] = to_jsonable(msg) File "/home/honey/bitcoin/./contrib/message-capture/message-capture-parser.py", line 85, in to_jsonable elif slot in HASH_INT_VECTORS and isinstance(val[0], int): IndexError: list index out of range ``` Fix this by using the `all(...)` predicate rather to access the first element `val[0]` (which in the error case doesn't exist). ACKs for top commit: laanwj: Code review ACK42bbbba7c8
Tree-SHA512: 139ec6b90304a69f26ec731e6f12b216fa10e554f777505b61adfa1e569f6861a4a849159dd1eae7a1aa0427e8598af226b6f0c4015020dcac8ab109fbc35dba
This commit is contained in:
commit
a05876619a
1 changed files with 2 additions and 1 deletions
|
@ -79,7 +79,8 @@ def to_jsonable(obj: Any) -> Any:
|
|||
val = getattr(obj, slot, None)
|
||||
if slot in HASH_INTS and isinstance(val, int):
|
||||
ret[slot] = ser_uint256(val).hex()
|
||||
elif slot in HASH_INT_VECTORS and isinstance(val[0], int):
|
||||
elif slot in HASH_INT_VECTORS:
|
||||
assert all(isinstance(a, int) for a in val)
|
||||
ret[slot] = [ser_uint256(a).hex() for a in val]
|
||||
else:
|
||||
ret[slot] = to_jsonable(val)
|
||||
|
|
Loading…
Add table
Reference in a new issue