Skip to content

Commit

Permalink
Catch OverflowError (#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
guedou authored Sep 11, 2024
1 parent 1464fa9 commit 4b71ab8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scapy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,14 @@ def _read_packet(self, size=MTU):
if len(hdr) < 16:
raise EOFError
sec, usec, caplen, wirelen = struct.unpack(self.endian + "IIII", hdr)
return (self.f.read(caplen)[:size],

try:
data = self.f.read(caplen)[:size]
except OverflowError as e:
warning(f"Pcap: {e}")
raise EOFError

return (data,
RawPcapReader.PacketMetadata(sec=sec, usec=usec,
wirelen=wirelen, caplen=caplen))

Expand Down
5 changes: 5 additions & 0 deletions test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,11 @@ file = BytesIO(b"\xd4\xc3\xb2\xa1\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x0
l = rdpcap(file)
assert l[0][LDAP].summary() == "LDAP"

# Issue #69628 - 32-bit alternative
file = BytesIO(b'\xd4\xc3\xb2\xa1\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x01\x00\x00\x00%\xa8\xddfK\x1b\x05\x00\xca\xca\xca\xca*\x00\x00\x00\xff\xff\xff\xff\xff\xff\x86"\x11&\xab3\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01]\x80\x0f\x13*r\n\x00\x02\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
l = rdpcap(file)
assert len(l) == 0 or ARP in l[0]

= Read a pcap file with wirelen != captured len
pktpcapwirelen = rdpcap(pcapwirelenfile)

Expand Down

0 comments on commit 4b71ab8

Please sign in to comment.