Skip to content

fix(hip): make() without parameters writes Header Length 0, below the RFC 7401 minimum of 4 - #1191

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1189-hip-parameterless-length
Oct 7, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1189-hip-parameterless-length

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests

  • Followed the coding style (make pylint, make mypy, make isort) — not run in full; isort clean on the new test, mypy shows no errors on the changed lines

  • make test passes, and a test case covers the change — only the modules listed below

  • Added a changelog entry — N/A, added centrally

  • fix — corrects a defect


Closes #1189

make(parameters=None) now writes Header Length 4 (the two HITs, RFC 7401 §5.1). read() rejects a wire length below 4, because _prml = (len - 4) * 8 would be negative but still truthy. The parameters-present path (total // 8 + 4) was already correct. test_hip_unit.py:229 pinned the old 0 and now expects 4.

Probe, HIPv1 and HIPv2: before, ProtocolError: HIPv{1,2}: invalid format. After, 40 octets, length byte 4, and it parses back to info.length == 40.

New tests/protocols/internet/test_hip_parameterless_length_unit.py: 3 passed. With the make fix reverted, 4 subtests fail. With the read guard reverted, 2 subtests fail.
Each test_hip_* module and test_option_roundtrip_unit.py pass. tests/project: 389 passed, 1 skipped. run_unittest_leg.py protocols/internet: 487 tests, 0 failures.

… RFC 7401 minimum of 4

- make(): a parameterless header now writes Header Length 4, which covers
  the two 16-octet HITs (RFC 7401 §5.1), so it is 40 octets and parses back.
- read(): reject a wire Header Length below 4 up front, instead of passing
  a negative parameter length to _read_hip_param.
- test_hip_unit: update the assertion that pinned the old length of 0.

Closes #1189
@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 Oct 7, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on d37a27131: GOOD TO GO (ran on Sonnet; the author ran on Opus).

  • The bug reproduces on main: HIP(parameters=None, ...) raises HIPv1/HIPv2: invalid format.
  • Fixed on this branch: v1 and v2 each produce 40 octets with a length byte of 4, info.length == 40, and a byte-exact re-parse. I re-ran this myself.
  • The new read guard is message-only: lengths 0–3 already raised ProtocolError on main. Lengths 4–7 parse identically on both sides, for v1 and v2.
  • Fails without the fix: each new test fails without its half of the fix (4 and 2 subtests). run_unittest_leg.py protocols/internet: 487 tests, 0 failures.
  • Nit, separate from this PR: make() with an unpadded raw-bytes parameter still rounds Header Length down. That is existing behaviour on main, and RFC 7401 requires parameters padded to 8 octets.
  • UNVERIFIED: the RFC 7401 §5.1 wording was checked from memory, not re-fetched.

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

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Coverage: 88.90% (unit tier, Python 3.14, d37a27131, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18757 1034 2342 845 90.24%
pcapkit/corekit 1878 91 580 22 94.34%
pcapkit/dumpkit 142 0 42 0 100.00%
pcapkit/foundation 2442 102 852 39 94.38%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 15749 190 4008 165 98.17%
pcapkit/toolkit 487 65 144 1 85.42%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

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

@JarryShaw
JarryShaw merged commit 195485a into main Oct 7, 2026
41 checks passed
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 7, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 25, 2026
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(hip): make() without parameters writes Header Length 0, below the RFC 7401 minimum of 4

1 participant