Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
message-capture-parser.py crashes when a message type is valid UTF-8 but contains non-printable characters, instead of marking it "UNREADABLE" like it's supposed to.
The code does raise UnicodeDecodeError with no arguments. That doesn't work —
UnicodeDecodeError needs 5 args to construct, so this actually raises a TypeError,
which the except block below doesn't catch. Script dies mid-run.
Since output is only written after the whole file is processed, one bad message type loses the entire parse.
Repro: python3 -c " import struct msgtype = b'\x01bad' + b'\x00'*8 open('msgs_recv.dat','wb').write(struct.pack('<q', 1234567890) + msgtype + struct.pack('<i', 0))" python3 contrib/message-capture/message-capture-parser.py msgs_recv.dat
TypeError: function takes exactly 5 arguments (0 given)
Expected behaviour
Should output "msgtype": "UNREADABLE" and keep going, same as it already does for plain invalid UTF-8.
Fix: try: msgtype_tmp = msgtype.decode() except UnicodeDecodeError: msgtype_tmp = None msg_dict["msgtype"] = msgtype_tmp if msgtype_tmp and msgtype_tmp.isprintable() else "UNREADABLE"
Steps to reproduce
cd contrib/message-capture
Create a fake capture file with a non-printable message type:
python3 -c " import struct msgtype = b'\x01bad' + b'\x00'*8 open('msgs_recv.dat','wb').write(struct.pack('<q', 1234567890) + msgtype + struct.pack('<i', 0))"
Run the parser on it:
python3 message-capture-parser.py msgs_recv.dat
Script crashes with a TypeError instead of printing UNREADABLE and continuing.
Relevant log output
No response
How did you obtain Bitcoin Core
Compiled from source
What version of Bitcoin Core are you using?
master@5569887
Operating system and version
Windows 11 Pro 10.0.26200
Machine specifications
No response