Skip to content

fix(toolkit): dpkt misreads SYN/FIN/RST when the TCP NS bit is set #1618

Closed

Description

@JarryShaw

With engine='dpkt', a TCP segment with the NS bit set has its flags misread: a SYN reads as a FIN.

Repro on main (d6f627481): one valid SYN, data offset 5.

Engine NS set NS clear
default syn=1 fin=0 syn=1 fin=0
dpkt syn=0 fin=1 syn=1 fin=0
scapy syn=1 fin=0 syn=1 fin=0

Cause:

  • pcapkit/toolkit/dpkt.py:742 (and :807) does flags = bin(tcp.flags)[2:].zfill(8), then reads flags[5], [6] and [7].
  • In dpkt 1.9.8, tcp.flags is 9 bits wide, with NS as bit 8.
  • With NS set the string has 9 characters, so every index lands one bit low.

Expected: RST, SYN and FIN are read from the low octet, e.g. with tcp.flags & 0xFF or dpkt's TH_* constants. The result must not depend on NS or the reserved bits.

Found by the #1614 cross-review; I reproduced it. Blocked until #1614 merges, because it edits pcapkit/toolkit/dpkt.py.

Activity

  1. JarryShaw commented on Oct 10, 2026

    @JarryShaw
    OwnerAuthor

    Blocked until #1614 merges, because it edits pcapkit/toolkit/dpkt.py.

  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 10, 2026
  3. JarryShaw commented on Oct 10, 2026

    @JarryShaw
    OwnerAuthor

    Unblocked: #1614 merged. A worker is on it.

  4. 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 10, 2026
  5. moved this from Blocked to WIP in PyPCAPKiton Oct 10, 2026
  6. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 12, 2026
  7. added this to the PyPCAPKit v1.5 milestone on Oct 26, 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