{"record":{"id":"62aebb358897ed0f","repo":"cloudflare/cloudflared","slug":"datagram-response-is-an-invalid-size","errorCode":null,"errorMessage":"datagram response is an invalid size","messagePattern":"datagram response is an invalid size","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/datagram_errors.go","lineNumber":15,"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":"ErrDatagramResponseInvalidSize is returned by UDPSessionRegistrationResponseDatagram.UnmarshalBinary when the input slice is shorter than the fixed datagramSessionRegistrationResponseLen. The response format has a fixed layout (type byte, request ID, response code, error message field), so undersized input cannot be parsed. It signals a truncated or non-response datagram.","triggerScenarios":"Calling UnmarshalBinary on bytes with len(data) < datagramSessionRegistrationResponseLen, e.g. payload[:15] in tests, or feeding a payload-type datagram into the response parser.","commonSituations":"Reading a short QUIC stream/datagram chunk; dispatching datagrams to the wrong unmarshaler by type; a peer sending a corrupted or truncated registration response.","solutions":["Check len(data) >= datagramSessionRegistrationResponseLen before unmarshaling","Dispatch on the datagram type byte so only response datagrams reach this parser","Verify the peer version produces the same fixed response layout (protocol/version mismatch)"],"exampleFix":"// before\nunmarshaled := &v3.UDPSessionRegistrationResponseDatagram{}\nerr := unmarshaled.UnmarshalBinary(payload) // too short\n// after\nif len(payload) < v3.DatagramSessionRegistrationResponseLen {\n    return fmt.Errorf(\"response truncated: %d bytes\", len(payload))\n}\nerr := unmarshaled.UnmarshalBinary(payload)","handlingStrategy":"validation","validationCode":"if len(data) < datagramSessionRegistrationResponseLen {\n    return ErrTruncatedResponse\n}","typeGuard":null,"tryCatchPattern":"if err := resp.UnmarshalBinary(data); errors.Is(err, v3.ErrDatagramResponseInvalidSize) {\n    return fmt.Errorf(\"registration response truncated (%d bytes)\", len(data))\n}","preventionTips":["Verify fixed response length before parsing","Only feed response datagrams to this parser (check type byte)","Detect protocol/version mismatches that change the layout"],"tags":["quic","datagram","unmarshal","truncated"],"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"}