Skip to content

Commit a058766

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25367: [contrib] message-capture-parser: fix out of bounds error for empty vectors
42bbbba 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 ACK 42bbbba Tree-SHA512: 139ec6b90304a69f26ec731e6f12b216fa10e554f777505b61adfa1e569f6861a4a849159dd1eae7a1aa0427e8598af226b6f0c4015020dcac8ab109fbc35dba
2 parents 9e4fbeb + 42bbbba commit a058766

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

contrib/message-capture/message-capture-parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def to_jsonable(obj: Any) -> Any:
7979
val = getattr(obj, slot, None)
8080
if slot in HASH_INTS and isinstance(val, int):
8181
ret[slot] = ser_uint256(val).hex()
82-
elif slot in HASH_INT_VECTORS and isinstance(val[0], int):
82+
elif slot in HASH_INT_VECTORS:
83+
assert all(isinstance(a, int) for a in val)
8384
ret[slot] = [ser_uint256(a).hex() for a in val]
8485
else:
8586
ret[slot] = to_jsonable(val)

0 commit comments

Comments
 (0)