Skip to content

Reject IPv4 fragments and invalid packet lengths - #39

Merged
rigtorp merged 1 commit into
masterfrom
fix/reject-fragments-and-invalid-lengths
Oct 5, 2026
Merged

rigtorp merged 1 commit into
masterfrom
fix/reject-fragments-and-invalid-lengths

Conversation

@rigtorp

@rigtorp rigtorp commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Fragmented captures currently corrupt UDP payloads: the first fragment's UDP length describes the entire datagram, so sendto reads beyond the captured fragment. Later fragments are incorrectly interpreted as containing new UDP headers. A 3,000-byte ASCII payload reproduces corruption at byte 1,472 and an ASan heap-buffer-overflow.

This stops replay with a clear error on UDP IPv4 fragments (MF or nonzero offset) before reading a UDP header. It validates captured/original lengths, Ethernet/VLAN headers, IPv4 IHL/total length, and UDP header/length before sending. Packet headers are copied into aligned locals, and libpcap read errors are reported rather than treated as EOF. Valid large datagrams, IP options, VLAN tags, and Ethernet padding remain supported.

Added generated-capture regression tests for fragment variants, the original MTU reproducer, malformed/truncated lengths, valid large/maximum UDP payloads, empty UDP, IP options, and VLANs. Packet tests run in Linux and macOS CI; Linux timing tests remain enabled. The README documents fragment rejection and external reassembly with IPDefragUtil.

Validation: GCC Release and Clang Debug builds with warnings as errors passed all six CTest tests. Clang ASan/UBSan packet checks passed with leak detection enabled; the original reproducer now fails safely with the fragment diagnostic. The regression suite fails on the original code. Actionlint, installation, and git diff --check passed. Native macOS validation awaits CI; its smaller OS UDP limit is allowed only for the valid maximum-size send test.

Closes #36.

@rigtorp
rigtorp merged commit 3afc813 into master Oct 5, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

UDP packets over MTU contain corrupted bytes around the MTU limit

1 participant