Skip to content

fix(pcapng)!: keep malformed journal entries and short packet blocks as captured (#1413, #1414) - #1420

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1413-1414-pcapng-kept-as-captured
Oct 8, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1413-1414-pcapng-kept-as-captured

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Closes #1413
Closes #1414

Byte-exact rebuild (PCAPNG.from_data(PCAPNG(raw).info).data), before → after: journal binary field missing its closing \n 28→32 ⇒ 28; bare KEY 16→12 ⇒ 16; SPB original_len=3 + 8 octets 24→20 ⇒ 24; EPB/PB of length 12–28 → 32 (EPB-12 raised FormatError) ⇒ unchanged.

Tests: new tests/protocols/misc/test_pcapng_kept_as_captured_1413_1414_unit.py (6 tests; 16 subtests fail without the fix). pytest per module, all green; tests/project 399 passed, 1 skipped; leg: 1059 tests, 0 failures.

…as captured (#1413, #1414)

- Journal Export: a line with no terminating newline (e.g. a bare KEY), a
  binary field with a short length prefix or without its closing newline,
  and any entry whose parsed fields would not rebuild octet for octet now
  raise inside the walk, so the whole entry is kept as `entry_raw` and
  rebuilt verbatim, per the #1406 ruling. Lines are no longer stripped.
- SPB: packet data past `original_len` and its padding is kept, with a
  warning, as #1384 does for the snaplen.
- EPB/PB: a Block Total Length below the 32-octet minimum keeps the block
  body as `block_raw`, which make() writes back at the declared length.
- Tests that pinned the old lossy journal parses now assert the entry is
  kept as captured; new regression module for both issues.
@JarryShaw JarryShaw changed the title fix(pcapng): keep malformed journal entries and short packet blocks as captured (#1413, #1414) fix(pcapng)!: keep malformed journal entries and short packet blocks as captured (#1413, #1414) Oct 8, 2026
@JarryShaw
JarryShaw force-pushed the fix/1413-1414-pcapng-kept-as-captured branch from d8b013f to f0565f7 Compare October 8, 2026 13:44
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) breaking Breaks public-facing behaviour or API (apply alongside the type label) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Coverage: 89.44% (unit tier, Python 3.14, f0565f794, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18791 968 2352 869 90.90%
pcapkit/corekit 2038 89 634 25 94.76%
pcapkit/dumpkit 234 2 84 2 98.74%
pcapkit/foundation 2637 98 928 48 94.78%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16543 220 4442 184 98.04%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2342 1006 157 43.25%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at f0565f794. Sonnet reviewed d8b013ff0; git diff d8b013ff0 f0565f794 is empty (subject ! only). The author ran on Opus.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 8, 2026
@JarryShaw
JarryShaw merged commit 6c44166 into main Oct 8, 2026
41 checks passed
@JarryShaw
JarryShaw deleted the fix/1413-1414-pcapng-kept-as-captured branch October 8, 2026 17:23
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 8, 2026
JarryShaw added a commit that referenced this pull request Oct 8, 2026
…tured (#1422)

- SHB below 28 octets and IDB below 20 read their fixed fields past the
  Block Total Length and rebuilt at the full fixed size. The body is now
  kept as `block_raw`, which make() writes back at the declared length,
  as #1420 does for EPB/PB; fields the block holds are decoded, the rest
  read as zero, and options are empty.
- The schemas skip the length/length2 comparison for such blocks; the
  reader compares the real trailing copy itself.
- A 12-octet SHB has no room for its Byte-Order Magic, so it takes the
  byte order in which its Block Total Length reads as 12. A bad magic on
  any other length still raises ProtocolError.
- New regression module for #1422.
JarryShaw added a commit that referenced this pull request Oct 8, 2026
…tured (#1422) (#1425)

- SHB below 28 octets and IDB below 20 read their fixed fields past the
  Block Total Length and rebuilt at the full fixed size. The body is now
  kept as `block_raw`, which make() writes back at the declared length,
  as #1420 does for EPB/PB; fields the block holds are decoded, the rest
  read as zero, and options are empty.
- The schemas skip the length/length2 comparison for such blocks; the
  reader compares the real trailing copy itself.
- A 12-octet SHB has no room for its Byte-Order Magic, so it takes the
  byte order in which its Block Total Length reads as 12. A bad magic on
  any other length still raises ProtocolError.
- New regression module for #1422.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks public-facing behaviour or API (apply alongside the type label) fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

1 participant