Skip to content

fix(ipv6): CALIPSO make() writes a corrupt length on overflow and raises raw errors for a bad pad - #1409

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1408-calipso-make-validation
Oct 8, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1408-calipso-make-validation

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style (make pylint, make mypy, make isort) — not run
  • make test passes, and a test case covers the change — the new module, util/run_unittest_leg.py protocols/internet (566 OK) and tests/project (399 passed, 1 skipped)
  • Added a changelog entry — N/A, added centrally

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

Description of your pull request and other information

CALIPSO changes in HOPOPT and IPv6-Opts:

  • make() overflow: 8 + bitmap + pad > 255 now raises ProtocolError. Before, a 248-octet pad wrote length 00 and a 1000-octet pad wrote f0.
  • make() bad pad: a non-bytes pad now raises ProtocolError, not struct.error or TypeError.
  • make() bad bitmap: an octet out of 0–255 or not an int raised ValueError/TypeError, a str bitmap raised TypeError, and an int bitmap was misbuilt (4 became 4 zero octets). All now raise ProtocolError. A bool octet, which main wrote as 01, is now rejected too.
  • Reader, odd Cmpt Length (behaviour change): make() emitted it but the reader rejected it. RFC 5570 §5.2 sizes the bitmap in 32-bit quanta ("0 bits, 32 bits, 64 bits, 96 bits"), and §5.1.3 says why. So the reader now accepts it. It still rejects a Cmpt Length that Opt Data Len does not cover.

Valid input builds unchanged bytes. That covers the 255-octet boundary and any bytes-like object (bytearray, memoryview) or iterable of ints (tuple, list, range, a generator); each matches main's octets.

Tests: test_ipv6_calipso_make_validation_unit.py passes 7 tests and 56 subtests. On origin/main's two source files, 36 subtests fail (18 per protocol). The equal-output cases pass on both.

Closes #1408

@JarryShaw JarryShaw added the fix Pull requests that fix a defect (fix: subject prefix) label Oct 8, 2026
@JarryShaw JarryShaw added the review: pending No verdict for the current head - never reviewed, or the head moved since the last one label Oct 8, 2026
@JarryShaw
JarryShaw force-pushed the fix/1408-calipso-make-validation branch from 638cddb to 5a3cfb5 Compare October 8, 2026 03:58
@JarryShaw JarryShaw added 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 Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Coverage: 89.41% (unit tier, Python 3.14, c2280075a, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18791 968 2352 869 90.90%
pcapkit/corekit 2038 89 634 25 94.76%
pcapkit/dumpkit 234 2 84 2 98.74%
pcapkit/foundation 2637 98 928 48 94.78%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16443 219 4394 182 98.04%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2342 1006 157 43.25%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on 5a3cfb5cd: NEEDS CHANGES. One narrowing (Sonnet reviewed; author Opus).

  • The narrowing. The new bitmap type whitelist (bytes/bytearray/tuple/list) rejects inputs that build on main: memoryview(bytes(8)), range(8), a set, and a generator. That is a public-behaviour narrowing the issue never asked for. Accept any bytes-like object or iterable of ints, validate each element as 0–255 int (rejecting bool), and keep a bare int refused.

Everything else holds:

  • RFC 5570, fetched by the reviewer. §5.1.3 sizes the field "in 32-bit words", and §5.2 gives "quanta of 32-bit words (e.g., 0 bits, 32 bits, 64 bits, 96 bits)". So relaxing the reader to accept an odd Cmpt Length is correct; §5.1.8's "64-bit words" is the RFC contradicting itself.
  • Fuzz. 3,948 parse→from_data→pack cases. Every accepted input rebuilds byte-exact, 524 odd-cmpt_len inputs are newly accepted, and none is newly rejected.
  • make() and tests. Output for every valid bitmap and pad is byte-identical to main. The 255-octet boundary builds and 256 raises. Revert proof: 30 failed.
  • Leg. I re-ran protocols/internet myself at this head: 566/0.

@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 Oct 8, 2026
…ses raw errors for a bad pad

_make_opt_calipso in HOPOPT and IPv6-Opts now raises ProtocolError when
the bitmap plus pad would exceed the 255 octets Opt Data Len can count,
when pad is not bytes/bytearray, and when the bitmap is a bare int or
str or holds an octet that is not an int in 0-255. Bytes-like objects
and iterables of ints build unchanged.

_read_opt_calipso no longer rejects an odd Cmpt Length, which RFC 5570
section 5.2 permits and make() builds; it now rejects a Cmpt Length that
Opt Data Len does not cover.

Closes #1408
@JarryShaw
JarryShaw force-pushed the fix/1408-calipso-make-validation branch from 5a3cfb5 to c228007 Compare October 8, 2026 04:20
@JarryShaw

Copy link
Copy Markdown
Owner Author

Delta verdict on c2280075a: GOOD TO GO. This resolves the round-2 narrowing.

  • Accepted bitmaps. I checked this myself on both trees: memoryview, range, a generator and bytes bitmaps build byte-identical HOPOPT output to main (3b02 0710 … 0001020304050607 …).
  • Rejected inputs. A bare int, a str and a bool octet now raise ProtocolError. The bool octet built as 01 on main; the PR body states that narrowing, which matches the rule the other address fields follow.
  • Unchanged from the reviewed round. Everything else is as the cross-review covered it. Revert proof: 36 subtests fail. protocols/internet 566/0; tests/project 399.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Oct 8, 2026
@JarryShaw
JarryShaw merged commit 428e70f into main Oct 8, 2026
38 checks passed
@JarryShaw
JarryShaw deleted the fix/1408-calipso-make-validation branch October 8, 2026 12:55
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 8, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 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): CALIPSO make() writes a corrupt length on overflow and raises raw errors for a bad pad

1 participant