{"record":{"id":"14e52dde5adca4ad","repo":"cloudflare/cloudflared","slug":"errdatagramresponsemsgtoolargedatagram","errorCode":"ErrDatagramResponseMsgTooLargeDatagram","errorMessage":"datagram response error message length exceeds the length of the provided datagram","messagePattern":"datagram response error message length exceeds the length of the provided datagram","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/datagram_errors.go","lineNumber":17,"sourceCode":"package v3\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n)\n\nvar (\n\tErrInvalidDatagramType                 error = errors.New(\"invalid datagram type expected\")\n\tErrDatagramHeaderTooSmall              error = fmt.Errorf(\"datagram should have at least %d byte\", datagramTypeLen)\n\tErrDatagramPayloadTooLarge             error = errors.New(\"payload length is too large to be bundled in datagram\")\n\tErrDatagramPayloadHeaderTooSmall       error = errors.New(\"payload length is too small to fit the datagram header\")\n\tErrDatagramPayloadInvalidSize          error = errors.New(\"datagram provided is an invalid size\")\n\tErrDatagramResponseMsgInvalidSize      error = errors.New(\"datagram response message is an invalid size\")\n\tErrDatagramResponseInvalidSize         error = errors.New(\"datagram response is an invalid size\")\n\tErrDatagramResponseMsgTooLargeMaximum  error = fmt.Errorf(\"datagram response error message length exceeds the length of the datagram maximum: %d\", maxResponseErrorMessageLen)\n\tErrDatagramResponseMsgTooLargeDatagram error = fmt.Errorf(\"datagram response error message length exceeds the length of the provided datagram\")\n\tErrDatagramICMPPayloadTooLarge         error = fmt.Errorf(\"datagram icmp payload exceeds %d bytes\", maxICMPPayloadLen)\n\tErrDatagramICMPPayloadMissing          error = errors.New(\"datagram icmp payload is missing\")\n)\n\nfunc wrapMarshalErr(err error) error {\n\treturn fmt.Errorf(\"datagram marshal error: %w\", err)\n}\n\nfunc wrapUnmarshalErr(err error) error {\n\treturn fmt.Errorf(\"datagram unmarshal error: %w\", err)\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/datagram_errors.go#L1-L29","documentation":"ErrDatagramResponseMsgTooLargeDatagram is returned when unmarshaling a UDPSessionRegistrationResponseDatagram whose declared error-message length (read at bytes 18:20) exceeds the bytes actually remaining after the fixed 20-byte header (data[20:]). Unlike the maximum-size variant, the length is protocol-legal but the datagram is truncated: the message body does not fit in the provided buffer. UnmarshalBinary wraps it via wrapUnmarshalErr; match with errors.Is.","triggerScenarios":"Calling UnmarshalBinary on a UDPSessionRegistrationResponseDatagram where int(errMsgLen) > len(data[20:]) — the datagram was cut short after the header, or the length field was corrupted upward.","commonSituations":"MTU/truncation issues chopping datagrams in transit; buffer-slicing bugs upstream passing a partial payload; version mismatch where the peer writes a longer message format than expected; test fixtures with deliberately truncated payloads.","solutions":["Before unmarshaling, check len(data) >= 20 + declared message length and reject truncated buffers.","Use errors.Is(err, v3.ErrDatagramResponseMsgTooLargeDatagram) to detect truncated datagrams and request retransmission or drop.","Audit the read path that produced the buffer for off-by-one slicing that dropped trailing bytes.","Check for network equipment (MTU, UDP fragmentation) truncating datagrams."],"exampleFix":"// before\nerr := resp.UnmarshalBinary(buf)\n// after\nif len(buf) >= 20 {\n    msgLen := int(binary.BigEndian.Uint16(buf[18:20]))\n    if len(buf[20:]) < msgLen {\n        return fmt.Errorf(\"truncated response datagram: need %d, have %d\", msgLen, len(buf)-20)\n    }\n}\nerr := resp.UnmarshalBinary(buf)","handlingStrategy":"validation","validationCode":"func isCompleteResponseDatagram(data []byte) bool {\n    if len(data) < 20 {\n        return false\n    }\n    msgLen := int(binary.BigEndian.Uint16(data[18:20]))\n    return len(data[20:]) >= msgLen\n}","typeGuard":null,"tryCatchPattern":"if errors.Is(err, v3.ErrDatagramResponseMsgTooLargeDatagram) {\n    logger.Warn().Msg(\"truncated response datagram; discarding\")\n    return nil\n}","preventionTips":["Verify datagram completeness (header + declared message length) before unmarshaling.","Audit buffer slicing for off-by-one errors that drop trailing bytes.","Monitor for MTU/fragmentation issues if truncation recurs in production."],"tags":["quic","datagram","truncation","wire-format"],"backgroundTag":"unexpected-response-shape","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}