Skip to content

fix(pcapng): cut an unknown, custom or journal block the file truncates (#1984) - #1988

Merged
JarryShaw merged 2 commits into
mainfrom
fix/1984-cut-unknown-blocks
Oct 20, 2026
Merged

JarryShaw merged 2 commits into
mainfrom
fix/1984-cut-unknown-blocks

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — a bug fix

Description of your pull request and other information

An unknown block, Custom Block or systemd journal export block that the file cuts short no longer aborts extraction.

  • Cause: each of these types reads its body as one BytesField sized from the Block Total Length alone. Past MAX_ZERO_PAD_LENGTH, that field raises FieldValueError during PCAPNG.unpack, which happens before PCAPNG.read's _read_block_cut fallback can step in.
  • Fix: a single helper, held_body, now caps all three bodies at the octets the stream still holds. The block then gets the same "block truncated" warning as EPB/IDB/ISB/NRB/SPB, and the earlier frames survive. Below the limit, a cut block holds its captured octets in place of a zero-padded body. Well-formed blocks and builds are unchanged.

test_pcapng_cut_block_past_eof_1984_unit.py fails on main (12 failed) and passes here. Round trips stay byte-exact.

Closes #1984

…es (#1984)

- UnknownBlock.body, CustomBlock.data and SystemdJournalExportBlock.entry
  are each one BytesField sized from the Block Total Length. A length past
  the end of the file made that field declare the missing octets: within
  the zero-pad ceiling they were zero-filled, past it FieldValueError was
  raised inside the header schema, outside PCAPNG.read's _read_block_cut
  fallback, and the extraction lost every earlier frame.
- The new held_body callback bounds the span by what is left of the
  stream, so the body is the octets the file holds and PCAPNG.read reports
  the truncation as it does for every other block type. It is a no-op on
  well-formed blocks and on the packing path.
- Tests cover all three types above and below the ceiling, and check the
  earlier frames, the warning, the held body, and byte-exact rebuilds.

Closes #1984
@JarryShaw JarryShaw added the fix Pull requests that fix a defect (fix: subject prefix) label Oct 20, 2026
@JarryShaw JarryShaw added the review: running A cross-review is in flight against the current head - no verdict yet label Oct 20, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 20, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at a7af33d8d. A Sonnet review of 481d2b390 ran extract on seekable, mid-file, pipe and bare non-seekable streams, both with and without the pcapng engine's read-ahead. A cut block behaves the same in every case, and well-formed blocks match main. Cut blocks rebuild byte-exact to the octets held. a7af33d8d only drops one "now" from the test docstring.

@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 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.53% (unit tier, Python 3.15, a7af33d8d, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19597 881 2618 867 92.11%
pcapkit/corekit 2540 71 808 37 96.54%
pcapkit/dumpkit 276 3 100 3 98.40%
pcapkit/foundation 2918 23 1016 25 98.78%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17459 225 4600 190 98.10%
pcapkit/toolkit 872 36 298 10 95.21%
pcapkit/utilities 522 2 158 4 99.12%
pcapkit/vendor 4431 1995 1018 167 51.73%

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

@JarryShaw
JarryShaw merged commit 3aeabc6 into main Oct 20, 2026
57 checks passed
@JarryShaw
JarryShaw deleted the fix/1984-cut-unknown-blocks branch October 20, 2026 21:25
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 20, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 20, 2026
@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

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(pcapng): an unknown, custom or journal block cut off past the zero-pad limit aborts extraction

1 participant