Skip to content

fix(protocols): a payload layer parsed from a short stream rebuilds default-filled octets #1170

Closed

Description

@JarryShaw

Describe the bug
A payload layer parsed from a stream shorter than its own header is default-filled, so from_data rebuilds octets that were never captured. #1169 fixes only the zero-octet IPv4 case behind #1167.

To Reproduce

  • IPv6: a 40-octet header declaring a 168-octet UDP payload parses as IPv6:UDP:Raw and rebuilds to 48 octets. I re-ran this on main 1b0862e72. A header cut at 30 octets also gains UDP:Raw.
  • IPv4 with a partial UDP header: header plus 1 octet rebuilds to 28 octets against 21 captured; plus 4 octets, 28 against 24.
  • IPv4 header cut short: test.pcapng frame 3 has 18 captured octets but rebuilds to 20. The missing low half of dst is zero-filled, and nothing records the captured length.

Expected behavior
A layer parsed from too few octets should rebuild to what was captured, not to a default-filled header.

Additional context
_import_next_layer in internet.py, protocol.py and transport.py picks NoPayload only when length == 0. A short-stream guard is needed there and in UDP and the other next layers. Found by the #1169 cross-review. The fix touches the same files as #1169, so this waits on it.

Activity

  1. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Blocked until #1169 merges, because the fix touches ipv4.py and the shared _import_next_layer path that #1169 also changes.

  2. added
    fixPull requests that fix a defect (fix: subject prefix)
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    on Oct 7, 2026
  3. moved this to Blocked in PyPCAPKiton Oct 7, 2026
  4. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Unblocked: #1169 merged at 02:25Z. A worker is on it now.

  5. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    on Oct 7, 2026
  6. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Decision needed on #1171 (fixes #1170): what should a frame cut inside the IP header become?

    #1171 adds one shared guard. When fewer octets are captured than the next layer's header needs, the payload becomes Raw instead of a header padded out with zeros. That fixes the IPv6 and partial-UDP cases exactly. It also changes test.pcapng frame 3, which carries 18 of 20 IPv4 header octets:

    My recommendation is (1): it is the only option that rebuilds exactly what was captured, with no new public field. It does drop fields from truncated headers, though, so it is your call.

  7. added
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 7, 2026
  8. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Addendum to the decision above, from the #1171 cross-review. Option (1) drops real leading fields, not only fabricated trailing ones:

    That makes (1) a public-contract change for snaplen-truncated captures, so I have labelled #1171 breaking. A third option worth weighing:

    • (3) Keep the typed layer and flag it as truncated, so the real fields survive and the rebuild writes only the captured octets. That needs a new truncation flag, the same kind of public addition as (2).

    The code itself was reviewed GOOD TO GO: both ordering legs pass on the merged tree, and the 1612-frame sweep changes only frame 3.

  9. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Recorded: the maintainer merged #1171 at 03:24Z, which settles this as option (1). A frame cut inside a header now yields Raw and rebuilds exactly what was captured, and the typed fields of a truncated header are no longer exposed. The #1171 cross-review's remaining gaps (IPv6_Route/MH understated hints, ApplicationBase not routed through the guard) will be filed separately.

  10. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 7, 2026
  11. added this to the PyPCAPKit v1.5 milestone on Oct 25, 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

    fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions