Repository navigation
fix(toolkit): pypcapfile checks IPv4 and TCP headers as the default engine does (#1590, #1591, #1592, #1593, #1596, #1597) - #1600
Merged
Conversation
…ngine does (#1590, #1591, #1592, #1593, #1596, #1597) pcapfile 0.12.0 slices an IPv4 header at its IHL without a bounds check, never parses IPv4 options, and has no IPv6 or AH decoder, and the toolkit read a TCP Data Offset below 5 as 20 octets, so its inputs disagreed with the default engine's. - A TCP Data Offset below 5 words is no TCP (#1590). - An IPv4 header whose IHL runs past the packet is no IPv4 (#1591). - IPv4 options are judged by the default engine's own IPv4 parser, given the header alone and once per frame; a header it rejects is no IPv4 and no TCP (#1596). - ipv4_reassembly() finds IPv4 carried in IPv6, as the default engine takes a frame's first IPv4 layer; TCP inside it is still a tunnel (#1592). - TCP behind IPv4 AH headers is read past them (#1593), and behind the IPv6 extension headers the default engine dissects inside IPv4, each read by its own parser (#1597). There the TCP header must be one the default TCP parser accepts; a tunnel behind them warns. Closes #1590 Closes #1591 Closes #1592 Closes #1593 Closes #1596 Closes #1597
Owner
Author
|
Verdict: GOOD TO GO at
Non-blocking:
|
Contributor
|
Coverage: 89.72% (unit tier, Python 3.14,
Per-file detail: the |
This was referenced Oct 10, 2026
Closed
JarryShaw
added a commit
that referenced
this pull request
Oct 14, 2026
…1721) Third-party engines are best effort (#1687), so the pypcapfile code that exists only to match the default engine comes out: - revert #1682, #1600, #1575 and #1535, and the pypcapfile hunks of #1655, #1608 and #1605: reading loopback and raw-IP link types, the frame layer bound, the VLAN and tunnel walks, keying tunnelled TCP by the innermost header, stepping over AH and extension headers, and checking options with the default engine's parsers - keep the helpers the dpkt and scapy adapters import, unchanged, until their own reverts drop them; their docstrings no longer say pypcapfile asks the default engine's parsers too - re-land #1576, #1577, #1590 and #1591 as guards in _network and _transport, #1513's once-per-capture warning for TCP straight over IPv6, and #1667's packet2dict fix: an undecoded frame is reported as its octets, not as hex text twice as long - keep #1569's record reader and #1690's packet2timestamp - delete the three test modules those reverts added, the pypcapfile timestamp agreement class, and #1682's link-type warning test; the re-landed guards' tests assert constants - drop what the reverts removed from the docs, READ_LINKTYPES included, and say that TCP behind a VLAN tag, in a tunnel or behind an extension header (an IPv6 one, or AH in IPv4) is now left out without a warning The pypcapfile modules, test_new_engine_parity_runtime.py, test_engine_runtime.py, the timestamp module and the project guards pass on 3.11 (pypcapfile 0.12.0) and 3.14.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the change. Targeted selections only; see below.What is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
This follows #1575. The pypcapfile toolkit now reads these headers as the default engine does. All the changes are in
pcapkit/toolkit/pypcapfile.py.ipv4_reassemblyfinds IPv4 inside IPv6, behind extension headers or 6in6, because the default engine takes a frame's first IPv4 layer. TCP inside it is still a tunnel and still warns.Trade-off. Judging options with the default engine's parsers costs about 200 µs per frame that has them. 10k Router Alert frames take 2.61 s, against 0.49 s before. Each frame is parsed once across the three adapters, and frames without options are never parsed. A header the default parsers reject logs the same CRITICAL
ProtocolErrorthe default engine logs, once per distinct header since results are cached. A header rejected on length alone (Data Offset below 5, IHL past the packet, AH Payload Length 0, truncated TCP) logs nothing, where the default engine logs one. The warnings filters and the logger level are left as they were.Tests (3.11 parity venv / 3.14 repo venv):
75 passedon 3.11 and51 passed, 24 skippedon 3.14.main.pypcapfile.pystays at 100% on 3.11 and goes from 98.5% to 98.9% on 3.14.Closes #1590
Closes #1591
Closes #1592
Closes #1593
Closes #1596
Closes #1597