Skip to content

fix(pcapng): default a made EPB/PB/ISB timestamp without an AttributeError (#2362) - #2382

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2362-pcapng-default-timestamp
Oct 27, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2362-pcapng-default-timestamp

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — bug fix

Description

Closes #2362.

  • Problem: _make_timestamp picked a defaulted timestamp's clock by reading self.nanosecond, which resolves its interface through the parsed data model. A block being made has no such model yet, so make() without an explicit timestamp raised AttributeError: '_info' for every block that carries one — the Enhanced Packet Block, the obsolete Packet Block, and the Interface Statistics Block, through its own Timestamp field as well as its isb_starttime/isb_endtime options.
  • Fix: read the resolution from _get_resolution(interface_id) instead — the lookup the method already made for the scale; the offset keeps its own _get_offset(interface_id) — no new fallback, matching every other make-path lookup in this file.
  • Test: tests/protocols/misc/test_pcapng_epb_pb_default_timestamp_2362_unit.py covers all three block kinds defaulting their timestamp to the current time, scaling to the interface's declared resolution and offset, reading the correct interface rather than interface 0 in a multi-interface section, reading the nanosecond clock rather than the float one when resolution calls for it, and round-tripping. Each case raises AttributeError on the parent commit.

Note: make() of EPB/PB/SPB with ctx=None still raises a separate, pre-existing UnsupportedCall on _get_linktype — a different symptom in a different method, out of scope here; worth its own issue if not already tracked.

@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) labels Oct 27, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 27, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.5 milestone Oct 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: GOOD TO GO at bcdc8f83e (Sonnet). Fix confirmed correct and minimal — 482 explicit-timestamp cases byte-identical before/after, 6 resolutions + offset confirmed via independent struct decode, round-trips exact, mutation-verified (13 failures restoring the bug). ctx=None caveat confirmed real and separate (pre-existing, in the constructor's re-parse step, not pack/make).

Two corrections to my own commit message/PR body: "ISB via isb_starttime/isb_endtime" understates it — the ISB block's own Timestamp field crashes too, not just its options. And "the same lookup already made two lines later for the offset" is wrong — the pre-existing lookup reused for the scale is _get_resolution; the offset uses the separate _get_offset. Will fix both.

Two mutation survivors found (interface_id hard-coded to 0, and the time_ns-vs-float clock branch unpinned) — fix dispatched, plus the docstring-tense nit. Issue label flipped pending→wip.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19601 881 2620 867 92.12%
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 17456 218 4598 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
JarryShaw force-pushed the fix/2362-pcapng-default-timestamp branch from bcdc8f8 to 83d7234 Compare October 27, 2026 11:14
@JarryShaw

Copy link
Copy Markdown
Owner Author

Amended bcdc8f83e → 83d72341a: added 2 mutation-verified tests (multi-interface resolution, nanosecond-vs-float clock pinning), reworded the docstring to the #1103 convention, and corrected my own commit message's two slips — ISB's own Timestamp field crashes too (not just its options), and the offset reuses a different lookup (_get_offset) than the scale does, not "the same lookup". Issue label flipped pending→wip. 8/8 tests pass.

All findings now addressed.

…Error (#2362)

Problem: _make_timestamp picked a defaulted timestamp's clock by reading
self.nanosecond, which resolves its interface through the parsed data model.
A block being made has no such model yet, so make() without an explicit
timestamp raised AttributeError: '_info' for every block that carries one --
the Enhanced Packet Block, the obsolete Packet Block, and the Interface
Statistics Block, through its own Timestamp field as well as its
isb_starttime/isb_endtime options.

Fix: read the resolution from _get_resolution(interface_id) instead -- the
lookup the method already made for the scale; the offset keeps its own
_get_offset(interface_id) -- no new fallback, matching every other make-path
lookup in this file.

Test: tests/protocols/misc/test_pcapng_epb_pb_default_timestamp_2362_unit.py
covers all three block kinds defaulting their timestamp to the current time,
scaling to the interface's declared resolution and offset, reading the
correct interface rather than interface 0 in a multi-interface section,
reading the nanosecond clock rather than the float one when resolution calls
for it, and round-tripping. Each case raises AttributeError on the parent
commit.
@JarryShaw
JarryShaw force-pushed the fix/2362-pcapng-default-timestamp branch from 83d7234 to 384a4f6 Compare October 27, 2026 11:52
@JarryShaw

Copy link
Copy Markdown
Owner Author

Amended 83d72341a → 384a4f646: fixed the "Fix:" sentence (the offset keeps its own separate lookup, not "two lines later" — the real line gap is 12, not 2) and the remaining past-tense clause in the source docstring ("made a make... raise" → "would make... raise"). Prose-only, 8/8 tests pass.

All findings across both rounds now addressed.

@JarryShaw JarryShaw added the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 27, 2026
@JarryShaw
JarryShaw merged commit d854642 into main Oct 27, 2026
62 checks passed
@JarryShaw
JarryShaw deleted the fix/2362-pcapng-default-timestamp branch October 27, 2026 15:09
@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(pcapng): make(type=EPB/PB) without timestamp raises AttributeError on _info

1 participant