{"record":{"id":"74befa34dff54629","repo":"cloudflare/cloudflared","slug":"invalid-payload-size-provided","errorCode":null,"errorMessage":"invalid payload size provided","messagePattern":"invalid payload size provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/request.go","lineNumber":17,"sourceCode":"package v3\n\nimport (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"fmt\"\n)\n\nconst (\n\tdatagramRequestIdLen = 16\n)\n\nvar (\n\t// ErrInvalidRequestIDLen is returned when the provided request id can not be parsed from the provided byte slice.\n\tErrInvalidRequestIDLen error = errors.New(\"invalid request id length provided\")\n\t// ErrInvalidPayloadDestLen is returned when the provided destination byte slice cannot fit the whole request id.\n\tErrInvalidPayloadDestLen error = errors.New(\"invalid payload size provided\")\n)\n\n// RequestID is the request-id-v2 identifier, it is used to distinguish between specific flows or sessions proxied\n// from the edge to cloudflared.\ntype RequestID uint128\n\ntype uint128 struct {\n\thi uint64\n\tlo uint64\n}\n\n// RequestIDFromSlice reads a request ID from a byte slice.\nfunc RequestIDFromSlice(data []byte) (RequestID, error) {\n\tif len(data) != datagramRequestIdLen {\n\t\treturn RequestID{}, ErrInvalidRequestIDLen\n\t}\n\n\treturn RequestID{","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/request.go#L1-L35","documentation":"ErrInvalidPayloadDestLen is returned by RequestID.MarshalBinaryTo when the destination byte slice is smaller than the 16 bytes needed to hold the full request-id-v2 identifier. MarshalBinaryTo writes the hi/lo uint64 halves in big-endian order into data, so a short buffer would be overflowed; the library rejects it upfront.","triggerScenarios":"Calling id.MarshalBinaryTo(buf) where cap/len(buf) < 16 — e.g. reusing a buffer sized for the old 8-byte request-id format, allocating make([]byte, 8), or slicing a larger buffer with a window shorter than 16 bytes.","commonSituations":"Migrating code from the previous 8-byte request id encoding to 16-byte request-id-v2 without resizing buffers; reusing pooled buffers sized by a constant that wasn't updated; passing a nil slice.","solutions":["Allocate the destination with at least 16 bytes: make([]byte, 16) or use RequestID's MarshalBinary which sizes it correctly.","Update any buffer-size constant from 8 to 16 after the request-id-v2 migration.","Guard with len(buf) >= 16 before the call, or pre-size from a shared constant (e.g. datagramRequestIdLen).","If using MarshalBinaryTo on a pooled buffer, verify the pool's buffer size matches the new 16-byte id width."],"exampleFix":"// before\nbuf := make([]byte, 8)\nerr := id.MarshalBinaryTo(buf)\n// after\nbuf := make([]byte, 16)\nerr := id.MarshalBinaryTo(buf)","handlingStrategy":"validation","validationCode":"buf := make([]byte, 16)\nif len(buf) < 16 {\n    return errors.New(\"destination buffer too small for request id\")\n}\nerr := id.MarshalBinaryTo(buf)","typeGuard":"func fitsRequestID(buf []byte) bool { return len(buf) >= 16 }","tryCatchPattern":"if err := id.MarshalBinaryTo(buf); errors.Is(err, v3.ErrInvalidPayloadDestLen) {\n    buf = make([]byte, 16)\n    err = id.MarshalBinaryTo(buf)\n}","preventionTips":["Use id.MarshalBinary() instead of MarshalBinaryTo when you don't need a reusable buffer.","Derive buffer sizes from the library constant rather than hardcoding 8/16.","Audit buffer pools after migrating to request-id-v2."],"tags":["quic","datagram","request-id","buffer-size"],"backgroundTag":"value-out-of-range","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"}