{"record":{"id":"26f64533086cc019","repo":"cloudflare/cloudflared","slug":"invalid-length-slice-provided-to-unmarshal-d-ex","errorCode":null,"errorMessage":"invalid length slice provided to unmarshal: %d (expected 16)","messagePattern":"invalid length slice provided to unmarshal: (.+?) \\(expected 16\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quic/v3/request.go","lineNumber":81,"sourceCode":"\treturn 0\n}\n\n// Less reports whether id sorts before id2.\nfunc (id RequestID) Less(id2 RequestID) bool { return id.Compare(id2) == -1 }\n\n// MarshalBinaryTo writes the id to the provided destination byte slice; the byte slice must be of at least size 16.\nfunc (id RequestID) MarshalBinaryTo(data []byte) error {\n\tif len(data) < datagramRequestIdLen {\n\t\treturn ErrInvalidPayloadDestLen\n\t}\n\tbinary.BigEndian.PutUint64(data[:8], id.hi)\n\tbinary.BigEndian.PutUint64(data[8:], id.lo)\n\treturn nil\n}\n\nfunc (id *RequestID) UnmarshalBinary(data []byte) error {\n\tif len(data) != 16 {\n\t\treturn fmt.Errorf(\"invalid length slice provided to unmarshal: %d (expected 16)\", len(data))\n\t}\n\n\t*id = RequestID{\n\t\tbinary.BigEndian.Uint64(data[:8]),\n\t\tbinary.BigEndian.Uint64(data[8:]),\n\t}\n\treturn nil\n}\n","sourceCodeStart":63,"sourceCodeEnd":90,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/quic/v3/request.go#L63-L90","documentation":"RequestID.UnmarshalBinary requires exactly a 16-byte slice, since a RequestID is two big-endian uint64s (high/low). If the input slice is any other length, it returns this error rather than reading out of bounds. It is a strict format check to guarantee round-trip fidelity with MarshalBinary.","triggerScenarios":"Calling (*RequestID).UnmarshalBinary with a slice whose len != 16, e.g. after slicing a buffer incorrectly or decoding a truncated identifier.","commonSituations":"Decoding request IDs from truncated datagram payloads; off-by-one slicing of a larger buffer; passing an empty slice to reuse a RequestID variable.","solutions":["Ensure the input slice is exactly 16 bytes before calling UnmarshalBinary.","Slice the source buffer with data[offset:offset+16] using correct offsets.","Check that the producer serialized with RequestID.MarshalBinary (32 hex/16 bytes) and the payload wasn't truncated in transit.","In tests, use the output of MarshalBinary directly as the UnmarshalBinary input."],"exampleFix":"// before\nid.UnmarshalBinary(data[:10])\n// after\nif len(data) < 16 {\n    return fmt.Errorf(\"need 16 bytes, got %d\", len(data))\n}\nerr := id.UnmarshalBinary(data[:16])","handlingStrategy":"validation","validationCode":"if len(data) != 16 { return fmt.Errorf(\"expected 16 bytes for RequestID, got %d\", len(data)) }","typeGuard":"func validRequestID(data []byte) bool { return len(data) == 16 }","tryCatchPattern":"if err := id.UnmarshalBinary(data); err != nil {\n    return fmt.Errorf(\"corrupt request id: %w\", err)\n}","preventionTips":["Always slice exactly 16 bytes for RequestID","Round-trip via MarshalBinary in tests","Check truncation at transport layer","Use encoding/binary consistently big-endian"],"tags":["quic","request-id","deserialization"],"backgroundTag":"invalid-argument-format","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"}