Skip to content

fix(corekit): read a capture cut inside an option area as a short read (#2694) - #2731

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2694-option-area-cut
Nov 3, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2694-option-area-cut

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

A capture cut inside or before an option area was refused, sometimes loudly, where it should have been read as a short read.

  • OptionField.unpack: a cut inside the area now parses as a recorded short read through Schema's built-in, and an option whose fields run past its area is still refused (fix(protocols): a declared length running past the data is accepted and zero-filled on rebuild #1325). A new _accepts_cut hook lets PCAP-NG keep its cut area raw.
  • MH: every message type parses at every cut and rebuilds byte-exactly. A cut option is kept only if it rebuilds as captured; otherwise it is refused quietly. Odd-length options 44 and 48, BID Reference and Multi-Prefix CGA are refused quietly through a new item_list_length callback.
  • HOPOPT and IPv6-Opts (option 1 from the owner): a standalone cut parses as a short read, and make(len=) rebuilds the declared Hdr Ext Len.
  • IPv6 tells a cut from an overrun through __capture_cut__. A header that runs past a declared Payload Length stays quiet Raw, as on main. IP_Pseudo stops at a cut header.
  • Conventions: the short-read ruling is written into utilities-or-corekit.rst.

The new tests fail on main. The CALIPSO, SMF_DPD and MPL type-octet-only cut is #2727.

Closes #2694

#2694)

Under the #1325 guards OptionField.unpack refused a capture cut landing in
front of or inside an option area: "consumed no data", a FieldValueError
logged at CRITICAL and again by beholder inside IPv6, or "runs past the end of
the data". So MH(cut) raised for a cut inside its options or an LRI or UPA
message's reserved octets, and HOPOPT cut to 2 or 3 octets logged.

- OptionField.unpack: where the data ends short of the area, the list ends
  with the data, and an option it ends inside stands if its fields fit the
  area, so Schema.unpack records the cut. One past its area is still refused.
  A new _accepts_cut hook decides; PCAP-NG's OptionAreaField declines it.
- IPv6 tells each header it walks, as __capture_cut__ in its packet, whether
  the octets handed fall short of the Payload Length left. Where they do not,
  an option area the data ends inside runs past the Payload Length and is
  refused, so such a header stays Raw, quietly.
- MH, HOPOPT and IPv6-Opts keep a cut option only if its parser takes the
  zeros and its maker writes the captured octets back, else refuse it quietly.
  HOPOPT and IPv6-Opts read a cut header as its short read; their make()
  takes len, the Hdr Ext Len a cut header declared. IP_Pseudo stops its walk
  at a cut header.
- MH: a fixed-width item list a length leaves part of an item in, as an odd
  Flow Summary option, is a ProtocolError rather than a logged FieldValueError.
- The short-read ruling is on the utilities-or-corekit conventions page.
- Tests cover every MH type, HOPOPT and IPv6-Opts at every cut, alone and in
  IPv6, both sides of the Payload Length, and the quiet refusals; pins of the
  old refusals, #2477's and the LRI/UPA ones of #2676's test among them,
  follow the short read.

The new tests fail on 01f0634. protocols, corekit and project pass module by
module.

Closes #2694
@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) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 3, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 29dbcffe1, from a Sonnet re-review.

@JarryShaw
JarryShaw merged commit ab7be2f into main Nov 3, 2026
25 checks passed
@JarryShaw
JarryShaw deleted the fix/2694-option-area-cut branch November 3, 2026 05:47
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 3, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 3, 2026
JarryShaw added a commit that referenced this pull request Nov 3, 2026
- Breaking: FrameRecord is an Info and TLSKeyLog.entries a TLSKeyLogEntries
  data model, not dicts (#2734); a new entry with 1.5.1's behaviour, and
  pickles checked loading both ways.
- Fixed: MH's CGA Parameters maker builds a data model's raw extension and a
  schema without public_key_test (#2732), into the makers' Fixed entry.
- Fixed: a capture cut inside or in front of an option area reads as a short
  read in MH, HOPOPT and IPv6-Opts, and an odd item list raises ProtocolError
  (#2731, ab7be2f, which the merge of 07ceaf7 also brings in); the
  short-read ruling into the conventions entry.
- Old values measured against v1.5.1.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issues reporting a defect (set by the bug report template; a default, not an assessment)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(corekit): a capture cut inside an option area is refused, and loudly, instead of a short read

1 participant