Skip to content

fix(internet)!: read a cut after an IPv6 option's type octet as a short read (#2727) - #2737

Open
JarryShaw wants to merge 1 commit into
mainfrom
fix/2727-ipv6-option-type-cut
Open

JarryShaw wants to merge 1 commit into
mainfrom
fix/2727-ipv6-option-type-cut

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

A capture cut that left only the type octet of a CALIPSO, SMF_DPD or MPL option, in HOPOPT or IPv6-Opts, logged a FieldValueError, at CRITICAL inside IPv6. The option's length callback rejected the zero-filled length.

  • Schema.unpack hands the fields after a cut the record of where the data ended, as packet['__short_read__']. The record is popped at the start of each unpack, so it never leaks between siblings or packets. Schema._note_short_read takes the packet as an optional argument.
  • The four length callbacks in ipv6_option.py defer only when that record shows the data ended before the length field. Nothing is clamped. CALIPSO and SMF_DPD then read as a recorded short read and rebuild byte-exactly through info and to_dict(). MPL is refused quietly, because its parser rejects a length under 2, as fix(corekit): a capture cut inside an option area is refused, and loudly, instead of a short read #2694 pins for Router Alert.
  • Breaking: a malformed length in whole data raises ProtocolError where 1.5.1 raised FieldValueError. The two are siblings under BaseError and ValueError. Inside IPv6 such a header becomes quiet Raw instead of logging CRITICAL.

The new tests fail on main. A trial merge with #2711's commit passes both sides' new tests.

Closes #2727

…rt read (#2727)

In HOPOPT and IPv6-Opts, a capture cut leaving only the type octet of a
CALIPSO, SMF_DPD or MPL option logged "FieldValueError: ... invalid <X> option
length: 0", at CRITICAL and again by beholder inside IPv6: the callbacks sizing
the option refused the zero the cut left for Opt Data Len, before the short
read could record the cut.

- Schema.unpack gives the fields after the one the data ends inside the short
  read, as __short_read__ in their packet, a forward match included, and clears
  it as each unpack starts, so a nested schema finds only its own.
- calipso_pad_len, mpl_opt_pad_len, smf_i_dpd_id_len and smf_dpd_data_selector
  leave an Opt Data Len the data ends before to the short read. #2694's rule
  then keeps CALIPSO and SMF_DPD, and refuses MPL quietly, as its parser
  refuses the zero, as Router Alert's does.
- An Opt Data Len on the wire too short raises ProtocolError, not
  FieldValueError, so a header refused for it is refused quietly. The four
  helpers' documented Raises class moves: the breaking change.
- Schema._note_short_read takes packet as an optional argument, so a caller
  with none keeps the record on the schema alone.
- The utilities-or-corekit page says how a callback tells a cut.
- Tests sweep every option of both headers at every cut, alone and in IPv6;
  the pins of the FieldValueError move to ProtocolError.

The new tests fail on ab7be2f. protocols, corekit and project pass module
by module.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 3, 2026
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) breaking Breaks public-facing behaviour or API (apply alongside the type label) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at c15c0b70c, from a Sonnet review of 1f85293f9.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Coverage: 94.45% (unit tier, Python 3.15, c15c0b70c, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 21062 175 2914 156 98.58%
pcapkit/corekit 2861 76 916 37 96.80%
pcapkit/dumpkit 282 3 100 3 98.43%
pcapkit/foundation 3496 26 1214 32 98.77%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 22629 150 5872 123 99.03%
pcapkit/toolkit 961 26 342 8 96.62%
pcapkit/utilities 533 7 144 5 98.23%
pcapkit/vendor 5590 2286 1280 214 55.75%

Per-file detail: the coverage-html artifact of this run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks public-facing behaviour or API (apply alongside the type label) bug Issues reporting a defect (set by the bug report template; a default, not an assessment) review: good-to-go Cross-review at the current head says ready; CI state is separate

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

fix(internet): a cut leaving only the type octet of a CALIPSO, SMF_DPD or MPL option logs a FieldValueError

1 participant