Skip to content

fix(protocols): makers name the rejected argument and value in error messages - #2405

Merged
JarryShaw merged 1 commit into
mainfrom
fix-2296-maker-invalid-format
Oct 28, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix-2296-maker-invalid-format

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — bug fix

Description

Fixes #2296. _make_* builders that reject a bad caller-supplied argument reported the reader's parse-error text (invalid format), giving no indication of which argument was wrong or what value triggered it.

Covers every site named in the issue: all 11 identical flags guards plus _make_chunk_data/_make_param_hostname/_make_cause_invalid_stream in sctp.py; make/_make_opt_bad/_make_opt_auth/_make_opt_badf/_make_opt_pad in mh.py (also added the missing Raises:/Warns: docstring sections); _make_mptcp_capable in tcp.py; and the one surviving generic-message branch each in hip.py's _make_locator and pcapng.py's _make_block_dsb (the branches #2276/#2273 didn't touch).

Note: #2296's own repro calls _make_chunk_data(Chunk(0), flags=b'\x00\x00'), but that method has no flags parameter (it takes reserved/I/U/B/E) — the issue's exact wording was applied to the 11 makers that actually take flags, and _make_chunk_data got a data-shaped message instead.

Four other maker-side sites keep the generic text but weren't in #2296's checklist — HOPOPT._make_opt_pad, IPv6_Opts._make_opt_pad, HTTP.make, PCAPNG.make (the dispatcher, not _make_block_dsb) — tracked as a follow-up in #2406 rather than folded in here.

Test: tests/protocols/test_maker_invalid_format_messages_2296_unit.py (new, 22 tests/82 subtests, one class per site group, each pinning the full message text plus the maker's valid-input case; independently confirmed each of the 22 changed sites is caught individually by reverting it alone). Confirmed fail-without-fix: 66 failed/20 passed against unpatched pcapkit. tests/protocols/ in full: 0 failures, same skip baseline as main. mypy and pylint findings on the 5 touched files are unchanged from main.

@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) 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 Oct 28, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Supersedes #2404 for #2296 — same scope, but that PR's cross-review found a wrong-requirement message, under-tested guards, and an overclaim about coverage (see the comment there). This one pins every site individually and stays within the issue's own checklist. Thanks to @Qiu-LingYan for the first pass at this — if the fixes above land there instead, I'll close this one.

@github-actions github-actions Bot added this to the PyPCAPKit v1.5 milestone Oct 28, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 28, 2026
…messages

Several _make_* builders rejected a bad caller-supplied argument with the
reader's parse-error text ("invalid format"), which gives no indication of
which argument was wrong or what value triggered it. #2296.

- sctp.py: all 11 identical `len(flags) != 1` guards across the chunk
  makers, plus _make_chunk_data's empty-data guard, _make_param_hostname's
  NUL-termination guard, and _make_cause_invalid_stream's reserved-length
  guard.
- mh.py: make()'s unsupported-data-type guard, _make_opt_bad/_make_opt_auth's
  length guards, _make_opt_badf's empty-data guard, and _make_opt_pad's
  Pad1-length warning. Added the missing Raises:/Warns: docstring sections.
- tcp.py: _make_mptcp_capable now names which optional field was given
  without its predecessor.
- hip.py: _make_locator's fallback branch (the one site #2276 missed).
- pcapng.py: _make_block_dsb's fallback branch (the one site #2273 missed).

_make_chunk_data's flags= example in the issue doesn't match any real
parameter on that method (it takes reserved/I/U/B/E, not flags), so its
exact wording was applied to the 11 makers that do take flags, and
_make_chunk_data got a data-shaped message instead.

Test: tests/protocols/test_maker_invalid_format_messages_2296_unit.py (new,
22 tests/82 subtests, one class per site group); confirmed 66 failed/20
passed against unpatched pcapkit, each failure a message-text mismatch.
tests/protocols/ in full: 2011 passed/51370 subtests/0 failed. mypy and
pylint findings on the 5 touched files are unchanged from main.

Four other maker-side sites still use the generic text but aren't in
#2296's checklist -- HOPOPT._make_opt_pad, IPv6_Opts._make_opt_pad,
HTTP.make, PCAPNG.make -- tracked separately rather than folded in here.
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: GOOD TO GO at e11cdb91f → amended to d0fd8cdcd (Sonnet). Independently re-verified every #2404 finding against this PR: the _make_opt_auth message is mathematically exact (probed lengths 0–14), each of the 22 changed sites is individually pinned (reverting any one alone fails the suite, confirmed on 3 random SCTP sites + TCP), and the body makes no universal-coverage claim. Full tests/protocols/ run: 0 failures after generating sample fixtures, same skip baseline as main; mypy/pylint unchanged. Two non-blocking nits from the review — an imprecise site count and the 4 untouched-but-out-of-scope sites going unmentioned — fixed by amending the commit/PR body and filing #2406 for the latter.

@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 Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.72% (unit tier, Python 3.15, d0fd8cdcd, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19609 880 2620 867 92.12%
pcapkit/corekit 2596 74 818 37 96.51%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 3045 24 1062 26 98.78%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17576 195 4668 181 98.30%
pcapkit/toolkit 924 36 334 10 95.55%
pcapkit/utilities 502 7 144 5 98.14%
pcapkit/vendor 4449 1961 1020 167 52.64%

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

@JarryShaw
JarryShaw merged commit aba2478 into main Oct 28, 2026
63 checks passed
@JarryShaw
JarryShaw deleted the fix-2296-maker-invalid-format branch October 28, 2026 03:56
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 28, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 28, 2026
JarryShaw added a commit that referenced this pull request Oct 28, 2026
Follow-up to #2405, which left these out of #2296's checklist. #2406.

- hopopt.py / ipv6_opts.py: _make_opt_pad's Pad1-length warning, matching
  MH._make_opt_pad's text from #2405 (alias swapped).
- httpv2.py: HTTP.make's unsupported-frame-type guard.
- pcapng.py: PCAPNG.make's unsupported-block-type guard (the dispatcher,
  not _make_block_dsb, which #2405 already fixed).

Added the missing Raises: docstring section on the two make() guards,
matching #2405's MH.make/_make_block_dsb docstrings.

Test: tests/protocols/test_maker_invalid_format_messages_2406_unit.py
(new, 9 tests/18 subtests), plus a ReadersKeepInvalidFormat pin that
_read_opt_pad on both protocols still says "invalid format" -- the exact
twin of the maker guard changed here. Confirmed fail-without-fix: 12
failures against unpatched pcapkit, each a message-text mismatch.
tests/protocols/ in full: 2020 passed/51388 subtests/0 failed. mypy and
pylint findings on the 4 touched files are unchanged from main.
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) 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): makers reject bad arguments with the reader's 'invalid format' text

1 participant