contrib: fix crash in message-capture-parser.py on non-printable msgtype #35903

pull CapThunder19 wants to merge 1 commits into bitcoin:master from CapThunder19:fix-message-capture-parser-crash changing 1 files +2 −4
  1. CapThunder19 commented at 6:22 PM on August 5, 2026: none

    The unrecognized-message-type branch tries to fall back to "UNREADABLE" by doing raise UnicodeDecodeError with no arguments. That doesn't work UnicodeDecodeError needs 5 constructor arguments, so this actually raises a TypeError, which the surrounding except UnicodeDecodeError doesn't catch. The script crashes instead of labeling the message and continuing.

    Since output is only written after the whole capture file is processed, one bad message type loses the entire parse.

    This isn't just theoretical: v2 transport accepts message-type byte 0x7F (net.cpp, V2Transport::GetMessageType), which v1 rejects (protocol.cpp, IsMessageTypeValid). 0x7F is valid UTF-8 but not printable, so a peer sending an unrecognized v2 message type containing it produces a capture record that crashes the parser on the next 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)

    With this fix it correctly outputs "msgtype": "UNREADABLE" and exits 0.

    Note there's no automated test covering message-capture-parser.py's output (p2p_message_capture.py has its own separate structural parser and says this script "should be verified manually") likely why this went unnoticed. Verified manually with the repro above and confirmed the existing invalid-UTF-8 fallback path is unaffected.

    #35883

  2. contrib: fix crash in message-capture-parser.py on non-printable msgtype 241385f21c
  3. DrahtBot added the label Scripts and tools on Aug 5, 2026
  4. DrahtBot commented at 6:22 PM on August 5, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35903.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->


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