-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ethernet packet handling calls _unpack_data twice when EtherType > 1500 #671
Comments
So far I wasn't able to reproduce this. The print is called once every time. Running cPython 3.10.15 on OSX
|
Signed-off-by: Philip Axer <[email protected]>
Using this annotated code: https://github.com/philipaxer/dpkt/tree/bug/multiple_call_to_unpack with the following test:
I get:
By the way, it makes a difference if i pass a bytes or bytearray object as argv[0]. |
Ok so |
This is THE common case. Virtually all protocols are of this nature.
What evidence do you want? Wireshark a trace on your machine, open the PCAP with dpkt, parse the frames and you will run into this issue. However, this should be mostly a performance issue.
I think you are mixing two concepts. data and userdata and how they tie into the API. Also, I disagree to the 'mask the issue' statement. The code block has its justification, from what i can see. Looking at
However by the way this was put together it accidentally causes double-calls in the
I dont see an API documenation, except for a handful of examples. Thus, I cannot conclusivly judge if things break or not. With this, I leave it to you to decide the fate of this issue :) Unrelated to this, I dislike the inflexible handling of MPLS, VLANs and thus MACsec (see my PR). The tags are hardwired in the Ethernet parser and don't allow me to craft deliberatly broken tagging structures (broken double tagging for example or VLAN-in-clear style frames). Also, I would like to use broken tags to generate test vectors, but cannot do that right now. Thus, I am considering to propose an alternative Ethernet parser that implements this differently and allows more freedom. Would you/the team be open to accept an PR for an EthernetNG implemenation that has a different/breaking |
Most unit tests in dpkt are based on real-world examples taken from PCAPs. Take the 1st unit test in ethernet.py for example (test_eth). It's Ethernet II, THE most common, the data buffer is provided via args, and yet
Off topic here. Feel free to open a separate issue / PR. |
Describe the bug
Calling Ethernet(buf) will always internally double call the _unpack_data() chain.
The first call comes from
dpkt.Packet.__init__ --> self.unpack --> _unpack_data
The second call then comes later from within
dpkt.Ethernet.__init__
:At this point self.data is always set, since
dpkt.Packet.__init__
sets it to be an empty byte arrayTo Reproduce
Add a print into Ethernet's
_unpack_data
function and calle = Ethernet(buf)
with some Ethernet packet. You see it printed twice.Expected behavior
The decode chain should only be executed once.
Fix
replace
if self.data
withif kwargs.get('data', None):
in ethernet.pyIf we agree that this is an issue, I will create a PR
The text was updated successfully, but these errors were encountered: