New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Check msg type in msg capture is followed by zeros #25117
The head ref may contain hidden characters: "2205-test-zero-\u{1F69B}"
Conversation
See #21079 |
assert(len(msgtype) > 0) | ||
assert(msgtype in MESSAGEMAP) | ||
assert(len(remainder) == 0 or not remainder.decode().isprintable()) | ||
assert all(r == 0 for r in remainder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, yes, this is weird code. Agree the new formulation is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept 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 range
I'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
, or getcfcheckpt
.
Good point! May be better to use |
Thx, used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice, using rstrip is even simpler!
Code-review ACK faa5a7a
Checking that they are not printable is an odd (and wrong) way to check that all chars are zero.