Repository navigation
fix(protocol): main is red, IPv4 make() with an unparsable raw item no longer raises the wrapped error - #1395
Merged
Merged
Conversation
…o longer raises the wrapped error #1344 pads the IPv4 option area once at the end, so the schema now accepts octets read() then rejects (an option whose length runs past the area), and the reader's bare ProtocolError escaped the wrap #1352 put around the schema re-parse only. unpack() now wraps the read as well when the made header holds raw items, and the wrapped message carries the original one. The same escape is fixed for TCP, HOPOPT, IPv6-Opts, MH, SCTP and HIP. Closes #1394
Contributor
|
Coverage: 87.50% (unit tier, Python 3.14,
Per-file detail: the |
Owner
Author
|
Cross-review verdict on
Nit: a An earlier review run went past its time budget and was stopped before reporting; this verdict comes from a narrower re-run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Searched for similar pull requests
Followed the coding style —
isort -l100 -ppcapkitclean;pylint/mypyonprotocol.pyreport nothing new on the changed lines (the 117-colraisematches the pre-existing one)make testpasses, and a test case covers the change — only the modules listed belowChangelog entry — N/A, added centrally
fix— corrects a defectRoot cause. #1344 pads the IPv4 option area once, at the end. So
[b'\x02', b'\x94\x04\x00\x00']now packs as02 94 …: option 2 claims length 148. The schema accepts that, and_read_ipv4_optionsrejects it atipv4.py:659(IPv4: invalid format). That check runs inread(), outside thetrythat #1352 put around the schema re-parse only (protocol.py:737-742). Before #1344, each item got its own padding,02 01 01 00. That gave a negative data length, which raised inside thetry.Which side is right. #1352's side. The input is still malformed, so the test stays as it is.
unpack()now also wrapsread()when the made header holds raw items. The wrapped message adds the original error's text after a colon (… given to make(): IPv4: invalid format), so a regex on the reader's message still matches.Other protocols. The same escape happened in TCP, HOPOPT, IPv6-Opts, MH, SCTP and HIP. A fuzz of 400 raw items per protocol on
mainlet 517 bareread()errors out: IPv4 375, MH 70, TCP 36, HOPOPT 15, IPv6-Opts 13, SCTP 8. HIP's escape is the ESP_INFO case in the tests. With this fix, all of them are wrapped. Errors raised insidemake()itself are unchanged (TCP_make_tcp_optionsenum lookup, IPv6-Route type check).Tests. New module
tests/protocols/test_make_raw_item_read_unit.py, with 8 cases thatread()rejects, plus a well-formed guard. Revert proof: withgit show origin/main:pcapkit/protocols/protocol.pywritten over the file, all 8 subtests fail, plus the originaltest_unparsable_raw_item_raises_protocol_error. With the fix, these pass:test_protocol_make_unit.py: 12 passedprotocols/internet: 546 tests, OKprotocols --exclude protocols/internet: 968 tests, OKtests/project: 389 passed, 1 skippedContract note: the
ProtocolErrortext for a malformed rawmake()item now ends with the original message.Closes #1394