Skip to content
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

windows : memory error reading pcap file #368

Closed
massimosala opened this issue May 31, 2017 · 11 comments
Closed

windows : memory error reading pcap file #368

massimosala opened this issue May 31, 2017 · 11 comments

Comments

@massimosala
Copy link

with the attached file, the first 4 packets are read and on the 5th

File "C:\Python27\lib\site-packages\dpkt\pcap.py", line 318, in iter
buf = self.__f.read(hdr.caplen)
MemoryError

pcap.py first line

$Id: pcap.py 77 2011-01-06 15:59:38Z dugsong $

NOTE : wireshark opens and parses the file without warnings.

!!! I tried to attach the pcap file, zipped, but it fails. the raw file is 19 Kb, please fix the upload or give me an email to send it.

@brifordwylie
Copy link
Collaborator

@massimosala you can email me the pcap at [email protected]

@kbandla
Copy link
Owner

kbandla commented May 31, 2017

@massimosala also which OS+arch are you on?

I suspect the caplen for the pcap is corrupted (or wrong endian), leading python to read beyond file, leading to a MemoryError. We'll find out once we have a look at the pcap.

@massimosala
Copy link
Author

I sent now the file to Brian.
I am on Windows 7, google chrome, and I cannot upload the file here. And I am an IT tech, not a novice.

The file is written be me, from C#, after reading the docs.
Wireshark decodes and displays all the 84 packets, dpkt bails out at the 5th.

@massimosala
Copy link
Author

About caplen : do you mean a field in the file header or in the 5th packet header ?

@massimosala
Copy link
Author

Now I am trying with other packets, captured by tcpdump on a linux box : same "memory error".
So it can be about endianess and the bug is in dpkt or tcpdump ....

@massimosala massimosala changed the title memory error reading pcap file, type DLT_IPV4 windows : memory error reading pcap file May 31, 2017
@massimosala
Copy link
Author

Python 2.7.10

@brifordwylie
Copy link
Collaborator

Here's the pcap in question
dpkt_memory_error.zip

@kbandla
Copy link
Owner

kbandla commented May 31, 2017

@massimosala I tested your pcap on windows 10 and it works just fine.

@kbandla
Copy link
Owner

kbandla commented May 31, 2017

Solution: In windows, you open binary files in 'rb' mode. That should fix this.

f = open('test.pcap', 'rb')   # open file in a binary mode
pcap = dpkt.pcap.Reader(f)

@massimosala
Copy link
Author

I am ashamed to not think of that. Can I suggest you to add this to the docs ? Many thanks for your help.

@kbandla
Copy link
Owner

kbandla commented Jun 1, 2017

@massimosala no worries; I created a quick PR to raise an Exception when his happens on Windows.

@kbandla kbandla closed this as completed Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants