{"record":{"id":"5317e1dcff7d9c55","repo":"canopy-network/canopy","slug":"unsupported-wire-type-d","errorCode":null,"errorMessage":"unsupported wire type %d","messagePattern":"unsupported wire type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/util.go","lineNumber":452,"sourceCode":"\t\t\tif offset+8 > len(b) {\n\t\t\t\treturn fmt.Errorf(\"truncated fixed64 field\")\n\t\t\t}\n\t\t\toffset += 8\n\t\tcase protowire.BytesType:\n\t\t\tl, n := protowire.ConsumeVarint(b[offset:])\n\t\t\tif n < 0 {\n\t\t\t\treturn fmt.Errorf(\"invalid length-delimited size at offset %d\", offset)\n\t\t\t}\n\t\t\toffset += n\n\t\t\tif l > protoMaxFieldBytes {\n\t\t\t\treturn fmt.Errorf(\"length-delimited field exceeds max size: %d > %d\", l, protoMaxFieldBytes)\n\t\t\t}\n\t\t\tif l < 0 || offset+int(l) > len(b) {\n\t\t\t\treturn fmt.Errorf(\"length-delimited field exceeds buffer bounds\")\n\t\t\t}\n\t\t\toffset += int(l)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported wire type %d\", wireType)\n\t\t}\n\t}\n\treturn nil\n}\n\n// MarshalJSON() serializes a message into a JSON byte slice\nfunc MarshalJSON(message any) ([]byte, ErrorI) {\n\t// convert the message to json bytes\n\tjsonBytes, err := json.Marshal(message)\n\t// if an error occurred during the conversion\n\tif err != nil {\n\t\t// exit with wrapped error\n\t\treturn nil, ErrJSONMarshal(err)\n\t}\n\t// exit with json bytes\n\treturn jsonBytes, nil\n}\n","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/canopy-network/canopy/blob/ee8197d91dd410f6592cb650a94c925ee6dc8bad/lib/util.go#L434-L470","documentation":"prelightProtoBytes walks raw protobuf bytes tag-by-tag before actual decoding and only recognizes the four standard wire types (varint, fixed32, fixed64, bytes). Wire types outside this set (e.g. start/end group, types 3,4,6,7) cannot be safely skipped, so the library aborts with this error instead of attempting to Unmarshal corrupt or non-protobuf bytes.","triggerScenarios":"Calling lib.Unmarshal (directly or via any message FromBytes path) with a byte slice that is not valid protobuf for this schema — e.g. random/corrupt bytes, bytes from a different message type, or a hand-crafted payload using group wire types.","commonSituations":"Peer or RPC payloads corrupted in transit, deserializing a payload produced by an incompatible protocol version, feeding non-protobuf data (JSON, hex) into a protobuf decode path, or fuzzing/malicious input.","solutions":["Verify the byte source: confirm the bytes were produced by this library's Marshal (protobuf) and not truncated or altered in transit","Check protocol/schema version compatibility between producer and consumer nodes","Log the offending payload (hex) and locate the offset where the unknown wire type appears to identify corruption","If the payload comes from an external peer, reject/drop the connection as the peer is sending malformed data"],"exampleFix":"// before: decoding bytes assumed to be protobuf but actually JSON/hex\nvar msg SomeMsg\nlib.Unmarshal(rawStringBytes, &msg)\n// after: validate the source format first\nif raw[0] != '{' {\n    if err := lib.Unmarshal(raw, &msg); err != nil { return err }\n} else {\n    return fmt.Errorf(\"expected protobuf bytes, got JSON\")\n}","handlingStrategy":"validation","validationCode":"func looksLikeProto(b []byte) bool {\n    if len(b) == 0 { return false }\n    // field tag varint: lowest 3 bits are wire type (0,1,2,5 are supported)\n    wireType := b[0] & 0x07\n    return wireType == 0 || wireType == 1 || wireType == 2 || wireType == 5\n}\nif !looksLikeProto(raw) { return fmt.Errorf(\"payload is not protobuf\") }","typeGuard":"func isProtoWireType(wt uint8) bool {\n    switch wt { case 0, 1, 2, 5: return true }; return false\n}","tryCatchPattern":"var msg pb.Message\nif err := lib.Unmarshal(raw, &msg); err != nil {\n    if strings.Contains(err.Error(), \"unsupported wire type\") || strings.Contains(err.Error(), \"invalid protobuf tag\") {\n        return ErrMalformedPeerPayload // drop/reject payload\n    }\n    return err\n}","preventionTips":["Only feed bytes produced by lib.Marshal into Unmarshal","Add a length-prefix/framing layer on the wire so payloads cannot be truncated or spliced","Log offending payloads (hex) on decode failure to detect corrupt peers early","Pin and verify protocol versions across nodes"],"tags":["protobuf","unmarshal","wire-format","corruption"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"ee8197d91dd410f6592cb650a94c925ee6dc8bad","analyzedAt":"2026-09-06T09:30:15.973Z","contentChangedAt":"2026-09-06T09:30:15.973Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}