23

Is it possible for UDP data to come to you corrupted? I know it is possible for it to be lost.

Net Citizen
  • 5,174
  • 8
  • 38
  • 50

6 Answers6

23

UDP packets use a 16 bit checksum. It is not impossible for UDP packets to have corruption, but it's pretty unlikely. In any case it is not more susceptible to corruption than TCP.

Pubby
  • 51,882
  • 13
  • 139
  • 180
Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
  • 3
    Technically the checksum is optional. From RFC 768: "An all zero transmitted checksum value means that the transmitter generated no checksum (for debugging or for higher level protocols that don't care)." – Andrew Johnson Sep 11 '08 at 18:34
  • Yes, BUT: a) the checksum, I guess, is always calculated for a normal not specifically configured UDP transmission, b) if the packet appears to have a correct length and checksum, then it is correct, or otherwise the system would not deliver such a packet to the caller. Right? – Ethouris Nov 15 '16 at 12:45
20

First of all, the "IP checksum" referenced above is only an IP header checksum. It does not protect the payload. See RFC 791

Secondly, UDP allows transport with NO checksum, which means that the 16-bit checksum is set to 0 (ie, none). See RFC 768. (An all zero transmitted checksum value means that the transmitter generated no checksum)

Thirdly, as others have mentioned, UDP has a 16-bit checkSUM, which is not the best way to detect a multi-bit error, but is not bad. It is certainly possible for an undetected error to sneak in, but very unlikely.

  • If the datagram arrives with no checksum, can the application ask for that information? – benc Sep 24 '09 at 18:01
  • Thanks for clarifying that IP checksum is only for the header. – RandomInsano Nov 07 '11 at 20:38
  • @RandomInsano Please note that poster had three points. Point 1 talks about "IP checksum", which is one level below UDP, point 3 says that UDP does have a checksum. So there are 2 checksums, IP that protects IP header, and UDP checksum that protects UDP header and data. So data is protected. – mikijov Mar 14 '13 at 16:26
  • @benc No. Checksum is handled by the OS and user will receive packet only if the packet passes checksum verification (or skips verification on zero checksum). User does not know if checksum was used or not. – mikijov Mar 14 '13 at 16:28
  • according to the RFC, the checksum is not just for the header: " Checksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data" – Tom Cumming Jan 05 '18 at 11:31
6

Possible? Absolutely. Undetected? Unlikely, since UDP employs a checksum that would require multiple-bit errors to appear valid. If an error is detected, the system will likely drop the packet - such are the risks of using UDP.

Kyle Cronin
  • 77,653
  • 43
  • 148
  • 164
5

UDP packets can also be delivered out of order, so if you are devising a protocol on top of UDP you have to take that into account as well.

Rob Walker
  • 46,588
  • 15
  • 99
  • 136
3

A common form of "corruption" that affects unsuspecting programmers is datagram truncation. See "Unix Network Programming" by Stevens for more information (page 539 in 2nd ed.)

You might check the MSG_TRUNC flag...

oz10
  • 153,307
  • 27
  • 93
  • 128
1

Short answer: YES.

Detailed answer:

About 7 years ago(maybe 2011?) We found that UDP datagrams are unintentionally changed when a UDP datagram is exchanged between a computer in China and another one in Korea. Of course, Checksum in UDP packet header is also reculculated regarding to the payload change. There were no malware software in two computers.

We found that the unintentional change only occurs when these conditions match:

  • First several bytes of datagrams are similar to the previous datagram
  • Only occurse when UDP datagrams go from one nation to another

I don't the cause exactly, but I roughly guess it is China Golden Shield.

So we added datagram garbling algorithm into out software ProudNet and the problem went away. It is not difficult to implement. Just encode or obfuscate first several bytes of your datagram.

Hyunjik Bae
  • 2,721
  • 2
  • 22
  • 32