Skip to content

fix(ipv6-opts): SMF_DPD H-DPD with an empty hav raises IndexError instead of ProtocolError - #1194

Merged
JarryShaw merged 1 commit into
mainfrom
fix-1193-smf-dpd-empty-hav
Oct 7, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix-1193-smf-dpd-empty-hav

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests

  • Followed the coding style (pylint/mypy/isort on the changed files: nothing new on the touched lines, mypy clean, isort clean)

  • make test passes, and a test case covers the change (modules listed below)

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

  • fix — corrects a defect


Closes #1193. _make_opt_smf_dpd (HOPOPT and IPv6-Opts) now rejects an empty H-DPD hav before it sets the mode bit with hav[0] | 0x80.

  • Before: HOPOPT(next=59, options=[(Option.SMF_DPD, {'mode': SMFDPDMode.H_DPD, 'hav': b''})]) raises IndexError: index out of range. IPv6_Opts does the same.
  • After: ProtocolError: HOPOPT: [OptNo 8] empty Hash Assist Value (HAV) (IPv6-Opts: ... for the other class).
  • Parse side: _read_opt_smf_dpd never indexes hav. A wire H-DPD option with len=0 parses to hav=b'' without raising, so it is not this defect class and is left unchanged.
  • New test tests/protocols/internet/test_smf_dpd_empty_hav_unit.py: without the fix, 2 failed with IndexError. With the fix, 2 passed, 4 subtests passed.
  • Also run: test_smf_dpd_mode_rebuild_unit 4 passed; test_option_roundtrip_unit 6 passed; test_ipv6_extension_runtime 3 passed; tests/project 389 passed, 1 skipped; util/run_unittest_leg.py protocols/internet 493 tests, 0 failures.

…tead of ProtocolError

_make_opt_smf_dpd set the H-DPD mode bit with hav[0] | 0x80 and no length
check. HOPOPT and IPv6_Opts now reject an empty Hash Assist Value with a
ProtocolError naming the option, like the other SMF_DPD validation errors.

Closes #1193
@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 602960330: GOOD TO GO (ran on Sonnet; the author ran on Opus).

  • Root cause: an empty hav raised IndexError on main and now raises ProtocolError: … [OptNo 8] empty Hash Assist Value (HAV) in both classes. I re-ran this myself.
  • No other output changes: non-empty H-DPD (hav of 1, 4 and 16 octets) and all I-DPD cases build byte-identically on main and the PR. A missing hav key now also raises ProtocolError, which is the same fix.
  • Parse side: 3b00080080000000 parses to hav=b'' without raising. That leniency on read is acceptable, and it is not the same defect class.
  • Tests: the new test fails without the fix (2 subtests). run_unittest_leg.py protocols/internet: 493 tests, 0 failures.
  • Out of scope, filed separately:
    • an SMF_DPD option with len=0 at the end of the header raises TypeError;
    • RPL option 0x23 raises AttributeError.

@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, 602960330, 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 15759 190 4028 165 98.18%
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 e776271 into main Oct 7, 2026
41 checks passed
@JarryShaw
JarryShaw deleted the fix-1193-smf-dpd-empty-hav branch October 7, 2026 16:16
@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(ipv6-opts): SMF_DPD H-DPD with an empty hav raises IndexError instead of ProtocolError

1 participant