Skip to content

fix(protocols): a cut standalone IPv6 extension header rebuilds with values its parse did not read #2761

Closed

Description

@JarryShaw

Describe the bug
A standalone IPv6 extension header cut short parses with fewer octets in some fields than its rebuild holds. The rebuilt octets are exact, but from_data(info).info != info. The parse reads only the captured octets; the rebuild reads at the declared width (_uncaptured, #2703). Framed in IPv6, nothing differs.

Reproduction

from pcapkit.protocols.internet.ipv6_route.protocol import IPv6_Route
H = bytes([59,2,2,1, 1,2,3,4]) + bytes(15) + b'\x01'
p = IPv6_Route(H[:6]); r = IPv6_Route.from_data(p.info)
p.info.reserved, r.info.reserved, bytes(r) == H[:6]  # (b'\x01\x02', b'\x01\x02\x00\x00', True)

Also: IPv6-Frag reserved_octet at cut 1 (b'' vs b'\x00'), HOPOPT/IPv6-Opts options gain a PadN the parse lacks (cuts 1, 2, 4–6), IPv6_Ext length at cut 1 (1 vs 2).

Expected behavior
The rebuild's info equals the parse's. test-coverage.rst (Round-Trip Invariants) requires a cycle to reproduce its input exactly; here the octets match, but the values do not.

Additional context
Likely site: Protocol.__post_init__ / replay_short_read: make a standalone short-read parse and its rebuild read the header the same way.

Activity

  1. added
    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 4, 2026
  2. added this to the PyPCAPKit v1.6 milestone on Nov 4, 2026
  3. moved this to Needs decision in PyPCAPKiton Nov 4, 2026
  4. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    Decision needed: does a round trip whose octets match but whose parsed values differ count as a defect? The Round-Trip Invariants section speaks of octets, so it doesn't settle this case.

    1. Defect, fix it. Make a standalone short-read parse and its rebuild read the header the same way, so from_data(info).info == info, and write the rule onto test-coverage.rst.
    2. Accept it. Octets are the invariant. Document that a standalone cut header's rebuild may hold zero-filled values the parse lacked.

    Recommendation: option 1. A rebuild that invents a PadN option, or zero-fills reserved, reports fields the capture never held. That is the same class of defect #2756 removed from lists.

    This touches pcapkit/protocols/protocol.py, and #2490's member reorder is running across the protocol modules now. So a worker starts on option 1 once that reorder's PR lands, unless you rule option 2 first.

  5. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    take 1

  6. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    Option 1, reconciled: a round trip has to reproduce the parsed values as well as the octets.

  7. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 4, 2026
  8. moved this from Needs decision to WIP in PyPCAPKiton Nov 4, 2026
  9. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    #2767 fixes every field this issue lists except one; that one needs a decision.

    The remaining gap: IPv6_Ext length at cut 1. The parse reads the header at 1 octet, while the rebuild reads it at the 2 octets that make() packs, and the data model does not record which width the parse was given. No shared rule fits all the cases. A cut Ethernet header differs only in its next layer. IPv6_Ext differs only in length. An IGMPv3 Report cut inside IPv4 needs IPv4's declared width.

    Recommendation: (a). It is the only shared fix. #2767 does not close this issue; the gap stays open here.

  10. added
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 4, 2026
  11. moved this from WIP to Needs decision in PyPCAPKiton Nov 4, 2026
  12. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Nov 4, 2026
  13. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    take (a)

  14. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    Option (a), reconciled: a cut header's data model records the width its parse read the header at, alongside __short_read__, and from_data rebuilds at that width. This closes the IPv6_Ext length gap at cut 1 without a per-protocol clamp.

    A worker is starting now; the PR will close this issue.

  15. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 4, 2026
  16. moved this from Needs decision to WIP in PyPCAPKiton Nov 4, 2026
  17. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions