Checking that they are not printable is an odd (and wrong) way to check that all chars are zero.
test: Check msg type in msg capture is followed by zeros #25117
pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2205-test-zero-🚛 changing 1 files +1 −5-
MarcoFalke commented at 2:16 PM on May 12, 2022: member
- MarcoFalke added the label Tests on May 12, 2022
-
MarcoFalke commented at 2:16 PM on May 12, 2022: member
-
in test/functional/p2p_message_capture.py:50 in fa395dffe3 outdated
48 | - remainder = raw_msgtype.split(b'\x00', 1)[1] 49 | + msgtype, remainder = raw_msgtype.split(b'\x00', 1) 50 | assert(len(msgtype) > 0) 51 | assert(msgtype in MESSAGEMAP) 52 | - assert(len(remainder) == 0 or not remainder.decode().isprintable()) 53 | + assert all(r == 0 for r in remainder)
laanwj commented at 2:44 PM on May 12, 2022:Huh, yes, this is weird code. Agree the new formulation is better.
theStack commented at 2:48 PM on May 12, 2022: memberConcept ACK
Note that the .split() assignment fails if the raw_msgtype doesn't contain any zeroes:
>>> msgtype, remainder = bytes.fromhex("aabbcc").split(b'\x00', 1) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: not enough values to unpack (expected 2, got 1)This problem is not introduced by this PR though; in the master branch it would occur as well:
>>> msgtype = bytes.fromhex("aabbcc").split(b'\x00', 1)[0] >>> remainder = bytes.fromhex("aabbcc").split(b'\x00', 1)[1] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of rangeI'm confused why this hasn't caused any problems. Whenever a msg-capture file is parsed that contains a message type that consumes the full 12 bytes (i.e. without zero), this should throw. This applies e.g. for ~
sendaddrv2~,getcfheaders, orgetcfcheckpt.laanwj commented at 2:51 PM on May 12, 2022: memberNote that the .split() assignment fails if the raw_msgtype doesn't contain any zeroes:
Good point! May be better to use
bytes.partitioninstead.test: Check msg type in msg capture is followed by zeros faa5a7a573MarcoFalke force-pushed on May 12, 2022MarcoFalke commented at 3:08 PM on May 12, 2022: memberThx, used
rstrip+ map lookup to check for trailing zerostheStack approvedtheStack commented at 3:27 PM on May 12, 2022: memberOh nice, using rstrip is even simpler!
Code-review ACK faa5a7a5735b054b5fd2dca6ef6fca2fad6edbde
MarcoFalke merged this on May 13, 2022MarcoFalke closed this on May 13, 2022MarcoFalke deleted the branch on May 13, 2022sidhujag referenced this in commit 237448ba7f on May 13, 2022DrahtBot locked this on May 13, 2023ContributorsLabels
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-04-17 06:13 UTC
More mirrored repositories can be found on mirror.b10c.me