Skip to content

fix(schema): a SchemaField reads its declared span but packs only the bytes its nested schema consumed #1292

Closed

Description

@JarryShaw

Describe the bug
Unpack hands the nested schema the whole declared span (schema.py:955-958, data.read(length)), but the nested schema reads less, and pack emits only what it consumed. The enclosing length field still says the old size, so the output is internally inconsistent and the unread octets are gone.

To Reproduce

class In(Schema):   x = UInt8Field()
class Out2(Schema):
    n = UInt8Field(); inner = SchemaField(length=lambda pkt: pkt["n"], schema=In); tail = UInt8Field()
Out2.unpack(bytes.fromhex("0302eeee04"), 5, None).pack().hex()   # "030204"

n is still 3 but eeee is lost.

Repro: /tmp/rtissues/corekit-repro.py (check D6) on origin/main 11ae68e.

Expected behavior
The unread octets are kept (as padding or a remainder) and re-emitted, or the span shrinks to match.

Found by the corekit round-trip audit (#1202). The repro was re-checked by an independent verifier, and I re-ran it on main at 11ae68ebf.

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

    @JarryShaw
    OwnerAuthor

    Blocked until the core schema PR for #1274/#1275/#1265/#1285 merges, because both edit protocols/schema/schema.py.

  3. added
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 7, 2026
  4. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Unblocked: #1331 merged at 20:41Z. Back to pending.

  5. added
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    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
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 7, 2026
  6. JarryShaw commented on Oct 7, 2026

    @JarryShaw
    OwnerAuthor

    Partly fixed by #1374 (parse → pack byte-exact). The parse → from_data half is filed as #1380; close this once both have merged.

  7. JarryShaw commented on Oct 8, 2026

    @JarryShaw
    OwnerAuthor

    Both halves have merged: parse → pack in #1374, parse → from_data in #1397 (which closed #1380). Closing.

  8. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 8, 2026
  9. 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