Skip to content

Commit a786307

Browse files
authored
Merge pull request #2789 from guedou/Issue_#2787
Stop processing a pcapng file when a block is malformed
2 parents 8646a86 + 23b5af3 commit a786307

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

scapy/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ def read_packet(self, size=MTU):
12341234
if (blocklen,) != struct.unpack(self.endian + 'I',
12351235
self.f.read(4)):
12361236
warning("PcapNg: Invalid pcapng block (bad blocklen)")
1237+
raise EOFError
12371238
except struct.error:
12381239
raise EOFError
12391240
res = self.blocktypes.get(blocktype,

test/regression.uts

+6
Original file line numberDiff line numberDiff line change
@@ -7269,6 +7269,12 @@ assert isinstance(pkt, Padding) and pkt.load == b'\xeay$\xf6'
72697269
pkt = pkt.payload
72707270
assert isinstance(pkt, NoPayload)
72717271

7272+
= Invalid pcapng file
7273+
7274+
from io import BytesIO
7275+
invalid_pcapngfile = BytesIO(b'\n\r\r\n\r\x00\x00\x00M<+\x1a\xb2<\xb2\xa1\x01\x00\x00\x00\r\x00\x00\x00M<+\x1a\x80\xaa\xb2\x02')
7276+
assert(len(rdpcap(invalid_pcapngfile)) == 0)
7277+
72727278
= Check PcapWriter on null write
72737279

72747280
f = BytesIO()

0 commit comments

Comments
 (0)