{"record":{"id":"b2c5fbf484db3d45","repo":"hyperledger/fabric","slug":"error-unmarshalling-serializedidentity","errorCode":null,"errorMessage":"error unmarshalling SerializedIdentity","messagePattern":"error unmarshalling SerializedIdentity","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":88,"sourceCode":"\n// UnmarshalSignatureHeader unmarshals bytes to a SignatureHeader\nfunc UnmarshalSignatureHeader(bytes []byte) (*common.SignatureHeader, error) {\n\tsh := &common.SignatureHeader{}\n\terr := proto.Unmarshal(bytes, sh)\n\treturn sh, errors.Wrap(err, \"error unmarshalling SignatureHeader\")\n}\n\n// UnmarshalIdentifierHeader unmarshals bytes to an IdentifierHeader\nfunc UnmarshalIdentifierHeader(bytes []byte) (*common.IdentifierHeader, error) {\n\tih := &common.IdentifierHeader{}\n\terr := proto.Unmarshal(bytes, ih)\n\treturn ih, errors.Wrap(err, \"error unmarshalling IdentifierHeader\")\n}\n\nfunc UnmarshalSerializedIdentity(bytes []byte) (*msp.SerializedIdentity, error) {\n\tsid := &msp.SerializedIdentity{}\n\terr := proto.Unmarshal(bytes, sid)\n\treturn sid, errors.Wrap(err, \"error unmarshalling SerializedIdentity\")\n}\n\n// UnmarshalHeader unmarshals bytes to a Header\nfunc UnmarshalHeader(bytes []byte) (*common.Header, error) {\n\thdr := &common.Header{}\n\terr := proto.Unmarshal(bytes, hdr)\n\treturn hdr, errors.Wrap(err, \"error unmarshalling Header\")\n}\n\n// UnmarshalConfigEnvelope unmarshals bytes to a ConfigEnvelope\nfunc UnmarshalConfigEnvelope(bytes []byte) (*common.ConfigEnvelope, error) {\n\tcfg := &common.ConfigEnvelope{}\n\terr := proto.Unmarshal(bytes, cfg)\n\treturn cfg, errors.Wrap(err, \"error unmarshalling ConfigEnvelope\")\n}\n\n// UnmarshalChaincodeHeaderExtension unmarshals bytes to a ChaincodeHeaderExtension\nfunc UnmarshalChaincodeHeaderExtension(hdrExtension []byte) (*peer.ChaincodeHeaderExtension, error) {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L70-L106","documentation":"This error is returned by protoutil.UnmarshalSerializedIdentity when proto.Unmarshal fails to decode the input bytes into an msp.SerializedIdentity message. The library wraps the underlying protobuf error with context so callers know which message type failed. It indicates the bytes are not a valid, complete, or correctly-versioned SerializedIdentity protobuf.","triggerScenarios":"Calling UnmarshalSerializedIdentity with empty bytes, truncated input, bytes of a different protobuf type (e.g. a Header or Proposal), corrupted certificates/identities read from a block or MSP directory, or input produced by a different Fabric/protobuf version with incompatible encoding.","commonSituations":"Parsing identity bytes extracted manually from an envelope or block; passing a PEM blob instead of the serialized identity; reading corrupted channel configuration; cross-version fabric-sdk/fabric-peer incompatibility; misconfigured MSP material.","solutions":["Verify the input bytes come from a serialized msp.SerializedIdentity (e.g. via id.Serialize() or an envelope's creator field), not a PEM or certificate blob.","Log len(bytes) and a hex/base64 dump of the input to confirm it is non-empty and consistent.","Regenerate the identity with a matching Fabric version (peer/MSP and SDK must agree on protobuf definitions).","Check for truncation/corruption during transport (base64 decode errors, string escaping, file offsets).","Handle the error path gracefully: reject the input and return a descriptive error instead of panicking on the nil-ish result."],"exampleFix":"// before\nsid, err := proto.Marshal(&common.Header{})\nidentity, _ := protoutil.UnmarshalSerializedIdentity(sid)\n// after\ncreator := envelope.SignatureHeader.Creator // actual SerializedIdentity bytes\nidentity, err := protoutil.UnmarshalSerializedIdentity(creator)\nif err != nil {\n    return fmt.Errorf(\"bad creator identity: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func validSerializedIdentity(b []byte) bool {\n    return len(b) > 0 && b[0] == 0x0a // SerializedIdentity: field 1 (Mspid), length-delimited\n}","typeGuard":"func isSerializedIdentity(v any) bool {\n    _, ok := v.(*msp.SerializedIdentity)\n    return ok\n}","tryCatchPattern":"sid, err := protoutil.UnmarshalSerializedIdentity(b)\nif err != nil {\n    return fmt.Errorf(\"invalid serialized identity (%d bytes): %w\", len(b), err)\n}","preventionTips":["Only feed bytes produced by id.Serialize() or the envelope's creator field into this API","Check for empty input before calling","Keep Fabric peer/MSP and SDK versions aligned","Avoid serializing identities through text formats (JSON/PEM) that alter the bytes"],"tags":["fabric","protobuf","unmarshal","identity","msp"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}