{"record":{"id":"e99d214934836628","repo":"cloudflare/cloudflared","slug":"datagram-unmarshal-error-w","errorCode":null,"errorMessage":"datagram unmarshal error: %w","messagePattern":"datagram unmarshal error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/datagram_errors.go","lineNumber":27,"sourceCode":"\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":9,"sourceCodeEnd":29,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/datagram_errors.go#L9-L29","documentation":"wrapUnmarshalErr wraps errors that occur while deserializing a received QUIC v3 datagram. It adds the 'datagram unmarshal error' prefix to any parse failure surfaced by UnmarshalBinary, such as truncated or malformed input. Callers should unwrap to find the underlying sentinel error.","triggerScenarios":"Calling UnmarshalBinary on a byte slice that is truncated, corrupted, or otherwise fails the datagram's structural parsing.","commonSituations":"Receiving datagrams from a peer over a lossy/misbehaving path; protocol version mismatch producing misaligned parsing; reading a partially-flushed datagram buffer.","solutions":["Validate the received buffer length and structure before calling UnmarshalBinary.","Unwrap with errors.Is against the ErrDatagram* sentinels to determine the exact parse failure.","Drop or log-and-ignore malformed datagrams rather than crashing the session.","Check both endpoints run a compatible cloudflared/protocol version."],"exampleFix":"// before\nerr := dg.UnmarshalBinary(data)\n// after\nif err := dg.UnmarshalBinary(data); err != nil {\n    if errors.Is(err, quicv3.ErrDatagramICMPPayloadMissing) {\n        logger.Warn().Msg(\"dropping malformed datagram\")\n        return nil\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if len(data) < minDatagramLen { return fmt.Errorf(\"datagram too short: %d\", len(data)) }","typeGuard":null,"tryCatchPattern":"if err := d.UnmarshalBinary(data); err != nil {\n    logger.Warn().Err(err).Msg(\"dropping malformed datagram\")\n    return nil\n}","preventionTips":["Validate buffer length before unmarshaling","Drop-and-log malformed datagrams instead of failing hard","Keep protocol versions aligned on both peers","Fuzz-test UnmarshalBinary with truncated inputs"],"tags":["quic","datagram","deserialization"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}