Files
Johannes Weiss ea000751b1 Reject too-small IPv4 packets in the PCAP parser test helper (#320)
### Motivation:

The readTCPIPv4 helper subtracted 20 from the IPv4 total length field in
UInt16 space before validating it. A total length below the header size
wraps around and traps with an arithmetic overflow.

A TCP/IPv4 packet is always at least 40 bytes (a 20 byte IPv4 header
plus a 20 byte TCP header), so a smaller total length is an illegal
packet that no further data can complete. Validate the total length
alongside the version and protocol checks and throw when it is too
small, then slice the payload. A regression test covers the lengths that
previously trapped.

These helpers only ever parse pcaps that WritePCAPHandler wrote, which
are always well formed, so the bug was dormant here. It becomes a real
crash when the helpers are reused to parse arbitrary captures.

### Modifications:

- Implement the check

### Result:

- More correct code, even though it's just a test helper
2026-07-17 10:59:41 +00:00
..