Repository navigation
fix(protocols)!: a declared length running past the data is accepted and zero-filled on rebuild - #1398
Merged
Conversation
Contributor
|
Coverage: 89.39% (unit tier, Python 3.14,
Per-file detail: the |
This was referenced Oct 8, 2026
Closed
Closed
…and zero-filled on rebuild - OptionField.unpack reads each option through a short-read proxy and raises ProtocolError when an option that began with octets present reads past the end of its data; one starting at the end keeps the end-of-option-list handling. A parent layer keeps the octets as captured and rebuilds them byte for byte. - PCAP-NG: bounded_option refuses a payload running past its area instead of clamping it, and OptionAreaField keeps a malformed option or record area whole as one bytes item. The block parses with no options, exposes the area as options_raw / records_raw, and make writes it back verbatim, so extraction continues and the round trip is byte-exact. BREAKING CHANGE: a truncated IPv4 or TCP option no longer parses with zero-filled data, and a malformed PCAP-NG option area is no longer clamped into options. The #431/#572 pins, the #1394 raw-item cases and the PCAP-NG clamp pins are rewritten to match. Closes #1325
JarryShaw
force-pushed
the
fix/1325-declared-length-overrun
branch
from
October 8, 2026 03:08
f984cb7 to
bc5d90f
Compare
JarryShaw
marked this pull request as ready for review
October 8, 2026 03:09
This was referenced Oct 8, 2026
fix(ipv4,tcp): a header length declared past the data zero-fills the missing octets on rebuild
#1404
Closed
Closed
Owner
Author
|
Cross-review on Why NEEDS CHANGES: "strict everywhere" is not fully met. None of the findings is a defect in this diff or a regression from
What the reviewer measured:
|
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.
mypy(no new errors on the touched source files) andisortwere run;pylintwas notmake testpasses, and a test case covers the change — not the full suite; legs belowWhat is the purpose of your pull request?
fix— corrects a defectfeat· [ ]perf· [ ]refactor· [ ]test· [ ]docs· [ ]ci· [ ]release· [ ]choreDescription of your pull request and other information
Closes #1325. Implements ruling (1), strict everywhere. Breaking: what a malformed option looks like in
infochanges.OptionField.unpackraisesProtocolErroronce an option that started with octets present reads past the data; an option starting exactly at the end keeps the EOOL handling (OptionField.unpack never returns for a well-formed HOPOPT header with an SMF_DPD option #431). Inside a parent layer the octets are kept as captured: raw extension data under IPv6, or aRawpayload elsewhere, as fix(protocols): a payload layer parsed from a short stream rebuilds default-filled octets #1171 does. Either way the frame rebuilds byte for byte.bounded_optionnow refuses a payload that runs past its area instead of clamping it. The newOptionAreaFieldkeeps such an option or record area whole, as onebytesitem. The block then parses with no options, the area is kept asoptions_raworrecords_raw, andmakewrites it back verbatim. Extraction no longer aborts, and the round trip is byte-exact.bounded_areastays: it only keeps the trailing Block Total Length out of the option area.test_a_truncated_option_still_parses_its_declared_lengthtests (OptionField.unpack never returns for a well-formed HOPOPT header with an SMF_DPD option #431, The #431 truncated-option short read has no test, only its empty-tail case does #572), four fix(protocol): main is red, IPv4 make() with an unparsable raw item no longer raises the wrapped error #1394 raw-item cases, and the clamp pins inPCAPNGOptionAreaBoundTestsandtest_custom_option_shorter_than_pen_is_rejected.tests/protocols/test_declared_length_overrun_unit.pycovers HOPOPT, IPv6-Opts, HIP, MH, TCP, IPv4 and SCTP.tests/protocols/misc/test_pcapng_option_area_kept_unit.pycovers SHB, IDB, EPB, ISB, NRB and extraction. They fail when the fix is reverted: 22 fail withorigin/main'scollections.py, and 56 fail withorigin/main's two PCAP-NG source files.Leg results, all 0 failures:
protocols/internet552,protocols --exclude protocols/internet1013,project586,corekit633.make_samplesprinted0 case(s) left out.