Skip to content

fix(protocols): rebuild a cut header with the next layer it parsed with (#2717) - #2759

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2717-cut-header-rebuild-next-layer
Nov 4, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2717-cut-header-rebuild-next-layer

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

A header the capture cut short is parsed at the octets captured, which hands its next layer a negative length, so the parse keeps Raw. from_data rebuilds it at its declared width (#2703), so the next layer's length is 0 and the rebuild got NoPayload. Same octets, but a different layer chain.

  • from_data now records (_short_of_header) when a cut header's data model kept Raw, and the new ProtocolBase._empty_next_layer keeps Raw for that rebuild.
  • A negative length with no octets past the header now goes straight to Raw, without dispatching on a zero-filled code. Such a Raw no longer carries the failed dispatch's error.
  • ProtocolBase, Internet, LinuxSLL and FRAD's SNAP path use the helper instead of their own checks.
  • The new test sweeps every class with a non-empty __proto__, cut at every octet. Besides the issue's cases, 22 more classes rebuilt a different chain on main (ARP family, AH, HIP, IPv6 extension headers, MH, VLAN, L2TPv2, LinuxSLL1/2, Loopback). It fails on main with 550 failures and passes here.
  • Not changed: when cut, some IPv6 extension-header fields (options, reserved, length) parse differently from their rebuild, though the chains match.

Closes #2717

@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 4, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.6 milestone Nov 4, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 4, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

NEEDS CHANGES at 96385b8db (Sonnet cross-review). The fix itself held up; only one docs gap needs changing.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 4, 2026
…th (#2717)

- A header the capture cut short, read at the octets captured, leaves its
  next layer a negative length, which kept it Raw. from_data reads the
  rebuild at the width the header declares (#2703), which leaves none, so
  the rebuild was NoPayload: the same octets, another layer chain.
- from_data tells the rebuild of a cut header whether its data model kept a
  Raw next layer, which only a parse short of the header's width does, as
  _short_of_header. ProtocolBase._empty_next_layer keeps that next layer Raw
  for the rebuild, and for a parse leaving a negative length with no octets
  past the header, now without dispatching on a code the cut may have read
  as zeros. ProtocolBase, Internet, LinuxSLL and FRAD's SNAP path use it in
  place of their own length checks.
- The Protocol page documents _empty_next_layer and the rebuild attributes
  its docstrings link: __reconstructing__, __short_read__, _uncaptured and
  _short_of_header.

test_cut_header_next_layer_2717_unit fails without the fix. The plain
unittest legs, both schema round trips, the short-read suites and the project
guards pass; the shipped captures parse the same chains.
@JarryShaw JarryShaw removed the review: needs-changes Cross-review at the current head says changes are required; see the verdict comment label Nov 4, 2026
@JarryShaw
JarryShaw force-pushed the fix/2717-cut-header-rebuild-next-layer branch from 96385b8 to eb8443f Compare November 4, 2026 06:13
@JarryShaw JarryShaw added review: pending No verdict for the current head - never reviewed, or the head moved since the last one review: running A cross-review is in flight against the current head - no verdict yet and removed review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Nov 4, 2026
@JarryShaw

JarryShaw commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner Author

GOOD TO GO at eb8443f3c

  • This round adds five lines to protocol.rst, and they are the only change: an automethod for _empty_next_layer, beside the other next-layer hooks, and autoattribute entries for __reconstructing__, __short_read__, _uncaptured and _short_of_header, which docstrings link to with :attr:.
  • A local docs build gave 0 warnings before and after, and all five anchors resolve. On this head, deploy-pages, Project tests and Lint pass.
  • The round-1 review of the code still stands, since pcapkit/ and tests/ are byte-identical to 96385b8db.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 20918 175 2908 156 98.57%
pcapkit/corekit 2890 76 928 37 96.83%
pcapkit/dumpkit 286 3 102 3 98.45%
pcapkit/foundation 3505 27 1216 32 98.75%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 22803 155 5912 127 99.00%
pcapkit/toolkit 961 26 342 8 96.62%
pcapkit/utilities 559 7 150 5 98.31%
pcapkit/vendor 5590 2286 1280 214 55.75%

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

@JarryShaw
JarryShaw merged commit 73f7307 into main Nov 4, 2026
69 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 4, 2026
@JarryShaw
JarryShaw deleted the fix/2717-cut-header-rebuild-next-layer branch November 4, 2026 13:53
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 4, 2026
JarryShaw added a commit that referenced this pull request Nov 4, 2026
- Fixed: a cut header's rebuild keeps the next layer its parse had, where
  1.5.x rebuilt a cut Ethernet header's Raw as NoPayload, and that Raw
  carries no error (#2759), a new entry; old values measured against v1.5.1.
- Amended unreleased entries (#2758): a cut list of schema items ends with
  the data, the item the cut lands inside zero-filled and none past it, in
  the ListField, IGMP and HTTP/2 SETTINGS entries, the last also rebuilding at
  its declared Length or a recomputed one once edited.
- Folded (#2755): a counted item the data ends inside reads as a quiet short
  read, into the ListField and IGMP entries.
- 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

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(protocols): a cut header parses with a Raw next layer but rebuilds with NoPayload

1 participant