Skip to content

fix(protocols): refuse an empty raw option in the makers (#2723) - #2728

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2723-empty-raw-items
Nov 3, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2723-empty-raw-items

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

An empty raw item given to a maker's raw-bytes branch was mishandled. The outcome depended on the maker: a bare IndexError or AttributeError, an item silently dropped beside a whole one, or, in PCAP-NG, an end-of-options or end-of-records marker written in its place. Each now raises ProtocolError, in the message shape #2708 uses for TCP.

  • IPv4, HOPOPT, IPv6-Opts: an empty option.
  • SCTP: an empty parameter or error cause.
  • PCAP-NG: a raw option or NRB record shorter than its 2-octet code.
  • MH: options, FID sub-options, QoS attributes, ANI and LCMP sub-options, and CGA extensions.
  • DCCP and HIP: an empty option or parameter. These were silently dropped.

A whole raw item still builds as given. The new tests fail on main.

Closes #2723

A raw-octets item given to a maker had its code read, or was kept, before its
length was checked, so an empty one escaped as a bare exception, was misread,
or was dropped.

- IPv4, HOPOPT, IPv6-Opts: _make_ipv4_options, _make_hopopt_options and
  _make_ipv6_opts read schema[0] of b'' and raised IndexError.
- SCTP: _make_sctp_parameters and _make_sctp_causes kept b'', which reached
  read() as a schema and raised AttributeError.
- PCAP-NG: _make_pcapng_options and _make_nrb_records read a 16-bit code from
  b'' as 0 and wrote an end marker; shorter-than-code octets are refused.
- MH: _make_mh_options, the FID, ANI and LCMP sub-option makers,
  _make_qos_attributes and _make_cga_extensions kept b'', which raised
  AttributeError alone and was dropped beside another item.
- DCCP, HIP: _make_dccp_options and _make_hip_param dropped b''.
- Each raises ProtocolError in the shape TCP's does since #2708; the makers'
  Raises and each released class's 1.6.0 versionchanged say so.

The six new modules fail on 01f0634 without the pcapkit/ change; the
internet, transport, misc, root protocols and project modules pass.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 3, 2026
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 2c305330e, from a Sonnet review of d18ebbf40.

  • After the review: two follow-up changes went in, and the commit was rebased onto 01f063467.
    • The DCCP and HIP refusals, which the reviewer suggested.
    • Rewording of the versionchanged bullets.
  • Rebase: it kept refactor(protocols)!: refuse fixed-size octets and timestamp counts the makers masked (#2676) #2691's bullets and clauses in place, and added this change's bullets beside them.
  • Tests: the six new modules fail on main (6, 3, 18, 24, 3 and 8 cases), and their whole-item controls pass there. All 341 modules pass.

@JarryShaw
JarryShaw merged commit 468f9c2 into main Nov 3, 2026
14 checks passed
@JarryShaw
JarryShaw deleted the fix/2723-empty-raw-items branch November 3, 2026 04:56
@github-project-automation github-project-automation Bot moved this to Done in PyPCAPKit Nov 3, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 3, 2026
JarryShaw added a commit that referenced this pull request Nov 3, 2026
….6.0 (#2449)

- Fixed: an empty raw option, parameter, cause, sub-option, attribute, CGA
  extension or PCAP-NG option or record shorter than its code raises
  ProtocolError (#2728), into the TCP and HIP makers' Fixed entry beside
  TCP's own; the IPv4, HOPOPT, IPv6-Opts, SCTP, MH, HIP and PCAP-NG
  outcomes measured against v1.5.1.
- Folded into unreleased entries: DCCP's empty raw option (#2728).
- No entry for the docstring-only 596dcfa and 6b63ee9, or the test-only
  219fbbc.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
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)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(protocols): an empty raw option raises IndexError in the IPv4, HOPOPT and IPv6_Opts makers

1 participant