Repository navigation
fix(toolkit): pyshark skips partial TCP headers and traces first fragments (#1611, #1612) - #1613
Merged
Merged
Conversation
Contributor
|
Coverage: 89.72% (unit tier, Python 3.14,
Per-file detail: the |
Owner
Author
|
Verdict: NEEDS CHANGES at What the review confirmed:
Two fixes:
|
…ments (#1611, #1612) - tcp_traceflow read tcp.flags_syn whether or not tshark had reported it, so a Data Offset below 5 or a header cut short raised a bare AttributeError and aborted the extraction; a header cut at 14-19 octets was traced where the default engine skips it. A TCP layer is now traced only if it carries tcp.urgent_pointer, the last field of the fixed header. - The engine left tshark's IP reassembly on, so TCP in a fragmented datagram was traced at its last fragment. FileCapture now gets ip.defragment and ipv6.defragment FALSE through override_prefs (PyShark.OVERRIDE_PREFS). That changes tshark's TCP sequence analysis on later frames of such a stream, which tcp_traceflow does not read. - Tests: fake and real-tshark tests in tests/toolkit/test_pyshark_unit.py, including a stream around fragmented segments; the 1581 first-fragment test no longer excludes pyshark; the FileCapture call assertion in test_runtime_engines.py names the new prefs. - Docs: the engine gap table says tshark's IP reassembly is off. Narrow runs pass on Python 3.11 (pyshark 0.6, tshark 4.6.9) and 3.14.
JarryShaw
force-pushed
the
fix/pyshark-bad-tcp-and-fragments
branch
from
October 10, 2026 17:52
c9b32c0 to
396140c
Compare
Owner
Author
|
Verdict: GOOD TO GO at The product code is unchanged since round 1, which the review already confirmed.
Non-blocking:
|
This was referenced Oct 10, 2026
JarryShaw
added a commit
that referenced
this pull request
Oct 14, 2026
Third-party engines are best effort (#1687), so the pyshark code that exists only to match the default engine comes out: - revert #1686, #1670 and #1642: the second tshark pass that read a frame's octets, the link type read from the capture file, the 64-layer bound, reading past tshark's 802.1Q limit, and keying a source-routed segment by ip.cur_rt - revert #1613's tshark preferences that turned IP reassembly off, with its FileCapture assertion in test_runtime_engines.py and its sentence in the engines index - keep #1613's partial-TCP-header guard and #1605's keying by the IP header that carries the segment - re-land #1671's crash fix: a TCP layer whose IP layer lacks ip.src or ip.dst is not traced, rather than raising AttributeError - delete the three test modules those reverts added and the agreement checks in test_pyshark_unit.py; the #1611 and #1671 checks assert constants The pyshark test modules, test_runtime_engines.py, test_engine_runtime.py and the project guards pass on 3.11 (tshark 4.6.9) 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
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeAdded a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A — centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
Closes #1611
Closes #1612
#1611.
tcp_traceflownow traces a pyshark TCP layer only if it hastcp.urgent_pointer. Octets 18–19 hold the last field of the fixed header. I checkeddissect_tcpinepan/dissectors/packet-tcp.cfor Wireshark 2.6.0, 3.0.0 and 4.6.0. In all three, tshark adds that field whenever the Data Offset is at least 5 and all 20 octets were captured. It is added after every fieldtcp_traceflowreads.AttributeError.#1612.
FileCapturenow runs tshark withip.defragmentandipv6.defragmentset to FALSE (PyShark.OVERRIDE_PREFS). As a result, TCP in a fragmented datagram is traced at its first fragment, both IPv4 and IPv6:(1, 2)/(6, 7), no longer(1, 5)/(6, 10).tcp.analysis.lost_segment, and theirtcp.completenesschanges. Those fields reach the frame recordspacket2dictbuilds.tcp_traceflowreads none of them, so tracing is unaffected, and a new test checks this on such a stream.ipv6.pcap.Tests.
tests/toolkit/test_pyshark_unit.py:The first-fragment test from #1605 no longer excludes pyshark.
test_runtime_engines.pynow asserts theFileCapturecall withoverride_prefs=PyShark.OVERRIDE_PREFS. Every new test fails with its fix reverted, except one guard:PySharkFixedHeaderTests::test_a_whole_header_is_tracedpasses on main too. The engine gap table in the docs is updated.