Skip to content

fix(reassembly): IPv4 reassembly raises IndexError for a fragment reaching octet 65,528 #1565

Closed

Description

@JarryShaw

Describe the bug
IPv4 reassembly raises IndexError for any fragment whose data reaches octet 65,528. That includes a legal last fragment: Fragment Offset 8191 (65,528 octets) carrying 7 octets ends exactly at the 65,535 limit.

Reproduction

from ipaddress import ip_address
from pcapkit.const.reg.transtype import TransType
from pcapkit.foundation.reassembly.data.ip import Packet
from pcapkit.foundation.reassembly.ipv4 import IPv4
bufid = (ip_address('192.0.2.1'), ip_address('198.51.100.2'), 7, TransType.UDP)
IPv4()(Packet(bufid, 1, 65528, 20, False, 27, b'H' * 20, bytearray(b'A' * 7), 1.0))
# IndexError: bytearray index out of range  (pcapkit/foundation/reassembly/ip.py:258)

It fails the same way with MF set and in non-strict mode. A fragment at offset 65,520 with 8 octets does not crash. I reproduced this on main.

Expected behavior
No crash. The fragment is buffered, and the datagram completes or stays PARTIAL as usual.

System information
Linux, CPython 3.14.8, main at cf6e78a45.

Additional context
The data buffer is 65,535 octets, but the received-bit table RCVBT has only 8,191 blocks, which covers octets 0–65,527. _detect_conflicts then indexes rcvbt[pos // 8] with pos // 8 == 8191 (ip.py:258, reached via ip.py:167). The table needs 8,192 blocks. Found while reviewing #1564; that PR does not fix it.

Activity

  1. added
    fixPull requests that fix a defect (fix: subject prefix)
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 10, 2026
  2. JarryShaw commented on Oct 10, 2026

    @JarryShaw
    OwnerAuthor

    The #1564 worker is fixing this in the same PR, because both changes are in pcapkit/foundation/reassembly/ip.py.

  3. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 10, 2026
  4. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 10, 2026
  5. 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