cloudflare/cloudflared · error
datagram response is an invalid size
Error message
datagram response is an invalid size
What it means
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.
Source
Thrown at quic/v3/datagram_errors.go:15
package v3
import (
"errors"
"fmt"
)
var (
ErrInvalidDatagramType error = errors.New("invalid datagram type expected")
ErrDatagramHeaderTooSmall error = fmt.Errorf("datagram should have at least %d byte", datagramTypeLen)
ErrDatagramPayloadTooLarge error = errors.New("payload length is too large to be bundled in datagram")
ErrDatagramPayloadHeaderTooSmall error = errors.New("payload length is too small to fit the datagram header")
ErrDatagramPayloadInvalidSize error = errors.New("datagram provided is an invalid size")
ErrDatagramResponseMsgInvalidSize error = errors.New("datagram response message is an invalid size")
ErrDatagramResponseInvalidSize error = errors.New("datagram response is an invalid size")
ErrDatagramResponseMsgTooLargeMaximum error = fmt.Errorf("datagram response error message length exceeds the length of the datagram maximum: %d", maxResponseErrorMessageLen)
ErrDatagramResponseMsgTooLargeDatagram error = fmt.Errorf("datagram response error message length exceeds the length of the provided datagram")
ErrDatagramICMPPayloadTooLarge error = fmt.Errorf("datagram icmp payload exceeds %d bytes", maxICMPPayloadLen)
ErrDatagramICMPPayloadMissing error = errors.New("datagram icmp payload is missing")
)
func wrapMarshalErr(err error) error {
return fmt.Errorf("datagram marshal error: %w", err)
}
func wrapUnmarshalErr(err error) error {
return fmt.Errorf("datagram unmarshal error: %w", err)
}
View on GitHub (pinned to 2253eeeb25)
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)
Example fix
// before
unmarshaled := &v3.UDPSessionRegistrationResponseDatagram{}
err := unmarshaled.UnmarshalBinary(payload) // too short
// after
if len(payload) < v3.DatagramSessionRegistrationResponseLen {
return fmt.Errorf("response truncated: %d bytes", len(payload))
}
err := unmarshaled.UnmarshalBinary(payload) Defensive patterns
Strategy: validation
Validate before calling
if len(data) < datagramSessionRegistrationResponseLen {
return ErrTruncatedResponse
} Try / catch
if err := resp.UnmarshalBinary(data); errors.Is(err, v3.ErrDatagramResponseInvalidSize) {
return fmt.Errorf("registration response truncated (%d bytes)", len(data))
} Prevention
- Verify fixed response length before parsing
- Only feed response datagrams to this parser (check type byte)
- Detect protocol/version mismatches that change the layout
When it happens
Trigger: Calling UnmarshalBinary on bytes with len(data) < datagramSessionRegistrationResponseLen, e.g. payload[:15] in tests, or feeding a payload-type datagram into the response parser.
Common situations: Reading a short QUIC stream/datagram chunk; dispatching datagrams to the wrong unmarshaler by type; a peer sending a corrupted or truncated registration response.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- datagram provided is an invalid size
- invalid datagram type expected
- payload length is too large to be bundled in datagram
- payload length is too small to fit the datagram header
- datagram response message is an invalid size
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/62aebb358897ed0f.
Report an issue: GitHub.