Skip to content

Decode replies using actual received length#54

Merged
aisk merged 1 commit into
masterfrom
fix-decode-use-actual-length
Jun 24, 2026
Merged

Decode replies using actual received length#54
aisk merged 1 commit into
masterfrom
fix-decode-use-actual-length

Conversation

@aisk

@aisk aisk commented Jun 24, 2026

Copy link
Copy Markdown
Owner

When decoding replies, the code previously passed the whole 2048-byte zero-filled buffer instead of slicing it to n, the number of bytes actually returned by recv_from. This changes all three decode paths to use &buffer[..n]: bare IPv4 ICMP, IPv4 with IP-header stripping, and IPv6.

As a result, the inner ICMP length extracted by IpV4Packet::decode reflects the real packet length rather than including trailing zero padding. Combined with the previously tightened length check in EchoReply::decode, short or malformed replies now return InvalidSize and get skipped by the loop, instead of having a bogus payload read out of the zero padding. The n == 32 branch still holds, since a RAW reply always carries an IP header and is therefore at least 52 bytes, so it can never be mistaken for the bare-ICMP branch.

@aisk aisk merged commit 7340bc4 into master Jun 24, 2026
3 checks passed
@aisk aisk deleted the fix-decode-use-actual-length branch June 24, 2026 15:18
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.

1 participant