{"record":{"id":"b8640e11a7ec7bc9","repo":"cloudflare/cloudflared","slug":"datagram-provided-is-an-invalid-size","errorCode":null,"errorMessage":"datagram provided is an invalid size","messagePattern":"datagram provided is an invalid size","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/datagram_errors.go","lineNumber":13,"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":"ErrDatagramPayloadInvalidSize is returned by UDPSessionPayloadDatagram.UnmarshalBinary when the incoming byte slice is either shorter than DatagramPayloadHeaderLen or longer than maxPayloadPlusHeaderLen. The parser must be able to read the fixed header and the declared payload within the slice bounds, so out-of-range sizes are rejected before parsing. It indicates a malformed or truncated datagram.","triggerScenarios":"Calling UnmarshalBinary on a buffer shorter than DatagramPayloadHeaderLen (e.g. payload[:16] when the header requires more), or a buffer exceeding maxPayloadPlusHeaderLen.","commonSituations":"Truncated datagrams received over the network; splitting datagrams at the wrong offset; feeding non-datagram garbage bytes into the parser; off-by-one slicing in test harnesses.","solutions":["Validate the datagram length against DatagramPayloadHeaderLen..maxPayloadPlusHeaderLen before calling UnmarshalBinary","Ensure the full QUIC datagram frame bytes are passed in one piece — do not split or reassemble them","Log the actual received length on errors.Is(err, v3.ErrDatagramPayloadInvalidSize) to detect malformed peers"],"exampleFix":"// before\nunmarshaled := v3.UDPSessionPayloadDatagram{}\nerr = unmarshaled.UnmarshalBinary(payload[:16]) // truncated\n// after\nif len(payload) >= DatagramPayloadHeaderLen && len(payload) <= maxPayloadPlusHeaderLen {\n    err = unmarshaled.UnmarshalBinary(payload)\n}","handlingStrategy":"validation","validationCode":"func canUnmarshalPayload(data []byte) bool {\n    return len(data) >= DatagramPayloadHeaderLen && len(data) <= maxPayloadPlusHeaderLen\n}","typeGuard":"func isWellSizedDatagram(data []byte) bool {\n    return len(data) >= DatagramPayloadHeaderLen && len(data) <= maxPayloadPlusHeaderLen\n}","tryCatchPattern":"if err := d.UnmarshalBinary(data); errors.Is(err, v3.ErrDatagramPayloadInvalidSize) {\n    logger.Debug().Int(\"len\", len(data)).Msg(\"dropping malformed datagram\")\n    return\n}","preventionTips":["Pass complete datagram frames in one slice — never partial reads","Dispatch by datagram type byte before choosing an unmarshaler","Log received lengths to spot truncating transports"],"tags":["quic","datagram","unmarshal","malformed"],"backgroundTag":"invalid-argument-value","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"}