{"record":{"id":"2d8fd4f5b6415a58","repo":"hyperledger/fabric","slug":"error-unmarshalling-chaincodeproposalpayload","errorCode":null,"errorMessage":"error unmarshalling ChaincodeProposalPayload","messagePattern":"error unmarshalling ChaincodeProposalPayload","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":172,"sourceCode":"// UnmarshalTransaction unmarshals bytes to a Transaction\nfunc UnmarshalTransaction(txBytes []byte) (*peer.Transaction, error) {\n\ttx := &peer.Transaction{}\n\terr := proto.Unmarshal(txBytes, tx)\n\treturn tx, errors.Wrap(err, \"error unmarshalling Transaction\")\n}\n\n// UnmarshalChaincodeActionPayload unmarshals bytes to a ChaincodeActionPayload\nfunc UnmarshalChaincodeActionPayload(capBytes []byte) (*peer.ChaincodeActionPayload, error) {\n\tcap := &peer.ChaincodeActionPayload{}\n\terr := proto.Unmarshal(capBytes, cap)\n\treturn cap, errors.Wrap(err, \"error unmarshalling ChaincodeActionPayload\")\n}\n\n// UnmarshalChaincodeProposalPayload unmarshals bytes to a ChaincodeProposalPayload\nfunc UnmarshalChaincodeProposalPayload(bytes []byte) (*peer.ChaincodeProposalPayload, error) {\n\tcpp := &peer.ChaincodeProposalPayload{}\n\terr := proto.Unmarshal(bytes, cpp)\n\treturn cpp, errors.Wrap(err, \"error unmarshalling ChaincodeProposalPayload\")\n}\n\n// UnmarshalTxReadWriteSet unmarshals bytes to a TxReadWriteSet\nfunc UnmarshalTxReadWriteSet(bytes []byte) (*rwset.TxReadWriteSet, error) {\n\trws := &rwset.TxReadWriteSet{}\n\terr := proto.Unmarshal(bytes, rws)\n\treturn rws, errors.Wrap(err, \"error unmarshalling TxReadWriteSet\")\n}\n\n// UnmarshalKVRWSet unmarshals bytes to a KVRWSet\nfunc UnmarshalKVRWSet(bytes []byte) (*kvrwset.KVRWSet, error) {\n\trws := &kvrwset.KVRWSet{}\n\terr := proto.Unmarshal(bytes, rws)\n\treturn rws, errors.Wrap(err, \"error unmarshalling KVRWSet\")\n}\n\n// UnmarshalHashedRWSet unmarshals bytes to a HashedRWSet\nfunc UnmarshalHashedRWSet(bytes []byte) (*kvrwset.HashedRWSet, error) {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L154-L190","documentation":"UnmarshalChaincodeProposalPayload wraps proto.Unmarshal failures of peer.ChaincodeProposalPayload bytes with this message. It is returned when the proposal payload bytes are malformed or of a different type. Callers typically get these bytes from a SignedProposal.ProposalPayload, so corruption or wrong-level extraction triggers it.","triggerScenarios":"Passing a SignedProposal instead of its ProposalPayload field, empty or corrupted proposal bytes, chaincode-side proposals crafted by a malicious/misbehaving client, or proto schema version mismatch.","commonSituations":"Chaincode handlers unpacking proposals during Invoke, UnpackProposal in SDK/peer code, endorsement validation rejecting client-signed proposals, or CLI tools building transactions with createSignedTxTwoActions.","solutions":["Pass SignedProposal.ProposalPayload exactly, not the whole SignedProposal or its signature","Validate the SignedProposal decodes and its proposal bytes are non-empty before unpacking the payload","Regenerate the proposal with a matching fabric SDK/protos version if bytes came from another component","Sanity-check ChaincodeInvocationSpec fields after unmarshal to catch semantic (not just wire) mismatches"],"exampleFix":"// before\ncpp, err := protoutil.UnmarshalChaincodeProposalPayload(signedProposalBytes)\n// after\ncpp, err := protoutil.UnmarshalChaincodeProposalPayload(signedProposal.ProposalPayload)\nif err != nil { return fmt.Errorf(\"invalid proposal payload: %w\", err) }","handlingStrategy":"validation","validationCode":"func validProposalPayload(sp *pb.SignedProposal) bool {\n    return sp != nil && len(sp.ProposalPayload) > 0\n}","typeGuard":"func safeUnmarshalCPP(b []byte) (cpp *peer.ChaincodeProposalPayload, ok bool) {\n    cpp, err := protoutil.UnmarshalChaincodeProposalPayload(b)\n    return cpp, err == nil && cpp != nil\n}","tryCatchPattern":"cpp, err := protoutil.UnmarshalChaincodeProposalPayload(signedProp.ProposalPayload)\nif err != nil {\n    return nil, fmt.Errorf(\"failed to unmarshal proposal payload: %w\", err)\n}","preventionTips":["Pass SignedProposal.ProposalPayload, never the whole SignedProposal or signature","Validate the signed proposal's structure before chaincode-level unpacking","Assume client proposals may be malicious: always handle the error path","Match SDK and peer proto versions when proposals cross components"],"tags":["protobuf","unmarshal","fabric","proposal"],"backgroundTag":"proto-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"}