Repository navigation
fix(protocols): convert capture timestamps without the platform's fromtimestamp limits (#2099) - #2111
Conversation
|
GOOD TO GO at
|
|
Coverage: 91.54% (unit tier, Python 3.15,
Per-file detail: the |
|
Ready to merge at
This closes #2099. |
|
|
|
Agreed,
|
…mtimestamp limits (#2099) datetime.fromtimestamp(ts, tz) breaks the instant down with the C library's gmtime(), and the Windows CRT's gmtime_s takes nothing before 1970 or after 3000, so in-range year-1 and year-9999 PCAP-NG timestamps took the invalid-timestamp fallback and were dated 1970. - new pcapkit.utilities.timestamp.fromtimestamp, not in compat, which holds backward-compatibility shims: split the float as CPython does (modf, half-even microseconds, carry), add to the epoch, tz.fromutc; ValueError/OverflowError as CPython on 64-bit Linux - use it in PCAPNG._read_timestamp, Frame.read, MH._read_opt_timestamp and MesgIDOption.post_process (MH had the same Windows gap) - document it on its own utilities page; the two tests that faked the module's datetime now fake the converter - new test emulates Windows' range and pins exact datetimes for both extremes, if_tzone rendering, MH pre-1970/post-3000, and the fallback Linux results identical to the stdlib on 1.2M fuzzed (value, tz) pairs.
73406d0 to
ebbd68a
Compare
|
Moved as requested, and rebased onto
A short delta review is running on the new head. |
|
GOOD TO GO at
|
|
Ready to merge at
This closes #2099. |
Per the owner's ruling on #2136, pcapkit.utilities.timestamp becomes pcapkit.utilities.datetime, reusing the stdlib name as utilities.logging and utilities.warnings do. The old path was added by #2111 and is in no release, so it is deleted with no re-export. - move the module and its docs page, and update the toctree - update the MH, PCAP frame and PCAP-NG importers and the tests - test that the new module exposes fromtimestamp and totimestamp, imports the stdlib datetime, and that the old path no longer imports
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— bug fixesDescription of your pull request and other information
Closes #2099. Windows'
gmtime_scovers only 1970-01-01 through 3000-12-31 UTC, and CPython turns itsEINVALintoOSError. So on the Windows leg (job 120605026883), PCAP-NG timestamps of year 1 and year 9999 fell back to 1970 withinvalid timestamp.pcapkit.utilities.compat.fromtimestampsplits the float exactly as CPython does (math.modf, microseconds rounded half to even, carry), adds it to the epoch, and appliestz.fromutc. It never calls the C runtime, so it needs no version gate.PCAPNG._read_timestamp: the bug itself.Frame.read: for consistency, since its range never fails on Windows._read_opt_timestampandMesgIDOption.post_process: they had the same gap for NTP times before 1970 and PMIPv6 times after 3000.ValueErrorfor NaN or a year outside 1–9999,OverflowErrorpasttime_tor out of range after the zone. Beyond a Cintof seconds, glibc raisesOSErrorwhile the helper raisesValueError. PCAP-NG, the only reader that can reach such values, catches both.fromtimestamp. The 504 that differ are that documented case.test_fromtimestamp_windows_range_2099_unitmakesfromtimestampraiseOSError(22)outside 0–3000, as Windows does. Without the fix 17 checks fail, including the CI log'sinvalid timestamp: -62135510400. With it, 8 tests and 60 subtests pass, and rebuilds stay byte-exact. The PCAP, PCAP-NG, MH, dumpkit, toolkit, compat andtests/projectfiles pass.