{"record":{"id":"55b8258a14152b0e","repo":"nats-io/nats-server","slug":"unsupported-type-d","errorCode":null,"errorMessage":"unsupported type: %d","messagePattern":"unsupported type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/proto.go","lineNumber":78,"sourceCode":"\nfunc protoScanFieldValue(typ int, b []byte) (size int, err error) {\n\tswitch typ {\n\tcase 0:\n\t\t_, size, err = protoScanVarint(b)\n\tcase 5: // fixed32\n\t\tif len(b) < 4 {\n\t\t\treturn 0, errProtoInsufficient\n\t\t}\n\t\tsize = 4\n\tcase 1: // fixed64\n\t\tif len(b) < 8 {\n\t\t\treturn 0, errProtoInsufficient\n\t\t}\n\t\tsize = 8\n\tcase 2: // length-delimited\n\t\tsize, err = protoScanBytes(b)\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unsupported type: %d\", typ)\n\t}\n\treturn size, err\n}\n\nfunc protoScanVarint(b []byte) (v uint64, size int, err error) {\n\tvar y uint64\n\tif len(b) <= 0 {\n\t\treturn 0, 0, errProtoInsufficient\n\t}\n\tv = uint64(b[0])\n\tif v < 0x80 {\n\t\treturn v, 1, nil\n\t}\n\tv -= 0x80\n\n\tif len(b) <= 1 {\n\t\treturn 0, 0, errProtoInsufficient\n\t}","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/proto.go#L60-L96","documentation":"In the protobuf wire-format scanner (server/proto.go), protoScanFieldValue switches on the field's wire type: 0 varint, 1 fixed64, 2 length-delimited, 5 fixed32. Any other wire type is invalid/unknown in the proto spec, so scanning returns this error.","triggerScenarios":"protoScanField (called during protobuf message scanning) encounters a field header whose wire-type nibble is 3, 4, 6, or 7 (e.g. legacy group types 3/4 or corrupt data).","commonSituations":"Corrupted or truncated protobuf payloads, hand-crafted byte slices in tests/fuzzing, or a peer sending a message encoded with deprecated group wire types.","solutions":["Verify the sender encodes standard protobuf wire types (0,1,2,5) only.","Re-encode the message with a maintained protobuf library instead of hand-rolling bytes.","Check for corruption/truncation in transport between peers.","If encountered in fuzzing, treat as expected invalid input and discard."],"exampleFix":"// before: field tag uses wire type 3 (group)\ntag = (fieldNum << 3) | 3\n// after: use length-delimited\ntag = (fieldNum << 3) | 2","handlingStrategy":"validation","validationCode":"// Validate wire type before scanning a protobuf field\ntyp := int(tag & 0x7)\nif typ != 0 && typ != 1 && typ != 2 && typ != 5 {\n    return errors.New(\"invalid protobuf wire type\")\n}","typeGuard":"func wireTypeSupported(typ int) bool {\n    switch typ {\n    case 0, 1, 2, 5:\n        return true\n    }\n    return false\n}","tryCatchPattern":"size, err := protoScanFieldValue(b, typ)\nif err != nil {\n    return fmt.Errorf(\"corrupt protobuf field (wire type %d): %w\", typ, err)\n}","preventionTips":["Encode with a maintained protobuf library, never hand-pack bytes.","Avoid deprecated group wire types (3/4).","Check message integrity over unreliable transports."],"tags":["protobuf","wire-format","encoding"],"backgroundTag":"invalid-protobuf-wire-type","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}