Skip to content

fix(protocol): raise on a short _read_unpack for every size (#2279) - #2349

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2279-read-unpack-short-read
Oct 27, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2279-read-unpack-short-read

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — bug fix

Description

Closes #2279.

  • Fix: _read_unpack, for sizes with no struct format code, now raises StructError on a short read instead of silently returning a smaller integer; quiet still returns the partial value.
  • Fail-without-fix: 4 failed on origin/main. Passing on the rebased head.

Problem: for a size with no struct format code, _read_unpack ran
int.from_bytes on whatever arrived, so a short read returned a smaller
integer where sizes 1, 2, 4 and 8 raise StructError.

Fix: check the length on the int.from_bytes path and raise the same
StructError without quiet; quiet still returns the partial value.

Test: test_read_unpack_short_read_fails_for_every_size.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 27, 2026
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: GOOD TO GO at cc955cbb0 (Sonnet).

  • Fix: _read_unpack now raises StructError on a short read for sizes with no struct code (3, 5, 6, 7, 9, 12, 16); sizes 1/2/4/8 are unaffected, and quiet=True still returns the partial value.
  • No caller relied on truncation: the three _read_protos overrides never see a short read in the generated samples (0 of 1616 frames hit the code path under a wrapper), and _read_unpack is not rendered in docs.
  • Fail-without-fix: 4 failed on origin/main. On the head, 16+83+143+44 passed.

@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 27, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.58% (unit tier, Python 3.15, cc955cbb0, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19599 881 2618 867 92.11%
pcapkit/corekit 2596 74 818 37 96.51%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 3029 23 1050 25 98.82%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17444 218 4588 185 98.15%
pcapkit/toolkit 914 36 334 10 95.51%
pcapkit/utilities 502 7 144 5 98.14%
pcapkit/vendor 4432 1988 1018 167 51.87%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

Ready to merge at cc955cbb0. Closes #2279.

  • Review: GOOD TO GO (Sonnet), posted 02:17:49Z.
  • CI: Required checks passed SUCCESS, 0 failures, KTLO clean.
  • Ordering leg: protocols gave 1962 tests with 0 failures, run with the PR merged into current main.
  • Merge state: mergeable.

@JarryShaw
JarryShaw merged commit 8a4cdd3 into main Oct 27, 2026
67 checks passed
@JarryShaw
JarryShaw deleted the fix/2279-read-unpack-short-read branch October 27, 2026 04:26
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 27, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issues reporting a defect (set by the bug report template; a default, not an assessment) fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(protocol): _read_unpack returns a short read as a smaller integer for odd sizes

1 participant