contrib: message-capture-parser.py crashes instead of labeling non-printable message types "UNREADABLE" #35883

issue CapThunder19 opened this issue on August 4, 2026
  1. CapThunder19 commented at 3:13 PM on August 4, 2026: none

    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

    1. cd contrib/message-capture

    2. 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))"

    3. Run the parser on it:

      python3 message-capture-parser.py msgs_recv.dat

    4. 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

  2. maflcko added the label Scripts and tools on Aug 4, 2026
  3. sedited commented at 6:30 PM on August 5, 2026: contributor

    This seems like it was discovered with AI as opposed to running this on an actual capture and getting an error. Since this is a contrib script, I'm not sure if that is relevant.

  4. CapThunder19 commented at 6:58 PM on August 5, 2026: none

    Yess, it was hand-built, not from a live capture. I'll build and test it against a real one to confirm.

  5. CapThunder19 commented at 8:02 PM on August 5, 2026: none

    Compiled bitcoind from source on my machine, started it as an actual running node with -capturemessages -v2transport=1, and connected a real Python p2p client to it over TCP connection with the full protocol handshake.

    sent a real wire message with type byte 0x7F - the node received it, didn't recognize it, and wrote it straight to msgs_recv.dat on disk, same as it would for any peer.

    Then ran the actual, unmodified message-capture-parser.py (pre-fix, bug still in it) against that real file. It crashed:

    TypeError: function takes exactly 5 arguments (0 given)

    exit code 1, dies right at the raise UnicodeDecodeError line.

  6. maflcko commented at 8:04 PM on August 5, 2026: member

    Thx, closing for now. There is no need to open an issue and a pull request. It should be fine to have the discussion in one thread only.

  7. maflcko closed this on Aug 5, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-11 19:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me