Skip to content

fix(protocols): hold a trial parse's warnings whenever beholder may replace it (#2516) - #2519

Open
JarryShaw wants to merge 1 commit into
mainfrom
fix/2516-trial-parse-warnings
Open

JarryShaw wants to merge 1 commit into
mainfrom
fix/2516-trial-parse-warnings

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect
  • feat — adds a feature
  • perf — changes performance, not behaviour
  • refactor — changes neither behaviour nor performance
  • test — tests only
  • docs — documentation only
  • ci — workflows or build tooling
  • release — bumps the version or rolls up a distribution
  • chore — anything else
  • const — regenerates constant or registry tables, members keeping their numeric values

Description of your pull request and other information

Closes #2516. Protocol._parse_next_layer held a trial parse's warnings only when the capture was shorter than the layer's length hint. A full-length layer that then raised still reported its SchemaWarnings before beholder replaced it with Raw, against #1580/#2308. One example is a mid-record TCP 443 segment: TLS's header read plus its SSLv2 fallback trial. #2339 had listed this case as left out.

One behaviour change to confirm: along a kept chain, an outer layer's warnings now report after its inner layers'. The set of warnings and their source lines are unchanged. This will be raised as a question here once the review lands.

…beholder (#2516)

Problem: _parse_next_layer held a trial's warnings only when the capture
was short of the layer's hint, but beholder replaces a layer that raises
at any length. A TCP segment to 443 that starts mid-record warned
"packet length < 0" twice (TLS's record header, then the SSLv2 fallback)
for a TLS layer kept as Raw.

Fix: hold whenever beholder is active, or the capture is short of the
hint. A raising layer's warnings go with it; a kept layer reports them
as its parse ends, after the layers it carries.

Test: tests/protocols/test_trial_parse_full_length_2516_unit.py; the #1580
test that pinned the leak now pins a parse outside beholder. Trial-parse,
TLS/SSL/DTLS and related project modules pass.
@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 1, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review (Sonnet) at 8673e66a7: GOOD TO GO. The root cause was reproduced on 94185da93: _short_of_hint(TLS, 1032) is false, so neither the TLS header-read warning (-24687) nor the SSLv2-trial warning (-10844) was held. The new and retargeted tests fail on main and pass here. A 6000-case differential fuzz on main and this head, under both always and error, found: identical chains, no new warning anywhere, drops only where a layer was replaced by Raw, 5 cases reordered, and 548 Raw errors now carrying the real parse failure instead of warning text.

Non-blocking, to fold in as a follow-up commit unless this merges first: the half of the docstring about holding outside beholder has no test; two consecutive sentences in the Note use "it" for beholder; and the new test docstrings use timed words ("now", "as before").

@JarryShaw

Copy link
Copy Markdown
Owner Author

Decisions needed before merge:

Q1. Warning order along a kept chain. Each held block reports when its parse ends, so an outer layer's warning now comes after its inner layers'. Example: IPv4 with a bad Security option carrying a cut Shim6 header. The set of warnings and their source lines are unchanged; the fuzz found 5 reordered cases in 6000. Options: 1. accept it (it is documented in the Note and pinned by a test); 2. redesign nesting, which collides with the error-filter rule that test_error_filter_chains_match_holding_nothing pins. Recommendation: 1.

Q2. pcapkit/toolkit/pypcapfile.py _default_extension_header catches a raising trial "as beholder does" but never sets _beholding, so the trial's warnings still replay (reproduced: HIP b0ff89ff0042ff1c warns -16 and -32, then returns None). It returns a tuple, not a Raw. Options: 1. the #2308 rule applies, so set _beholding around that call in a separate change; 2. it does not apply there. Recommendation: 1, because the trial's result is discarded on raise exactly as a beholder replacement is.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate needs: decision Waiting on the maintainer to decide — not blocked by other work and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 1, 2026
@JarryShaw JarryShaw moved this to Needs decision in PyPCAPKit Nov 1, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

take your recommendations on both questoins

@JarryShaw

Copy link
Copy Markdown
Owner Author

Owner took both recommendations. Q1: the new warning order along a kept chain is accepted as documented. Q2: the #2308 rule applies to pypcapfile._default_extension_header, so it gets its own change, #2526. This PR is ready to merge as it stands. The review's three non-blocking nits ride along with #2526 so this verdict stays valid.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Coverage: 93.94% (unit tier, Python 3.15, 8673e66a7, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 20087 144 2710 125 98.78%
pcapkit/corekit 2605 74 818 37 96.52%
pcapkit/dumpkit 281 3 100 3 98.43%
pcapkit/foundation 3194 27 1112 31 98.65%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 19906 213 5236 207 98.32%
pcapkit/toolkit 924 36 334 10 95.55%
pcapkit/utilities 502 7 144 5 98.14%
pcapkit/vendor 5009 2222 1148 182 52.31%

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

fix Pull requests that fix a defect (fix: subject prefix) 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(protocols): a TLS trial parse on TCP 443 that falls to Raw still emits SchemaWarnings

1 participant