{"record":{"id":"df450d48bd0fc725","repo":"hyperledger/fabric","slug":"could-not-unmarshal-chaincode-package-to-cds-or-si","errorCode":null,"errorMessage":"could not unmarshal chaincode package to CDS or SignedCDS","messagePattern":"could not unmarshal chaincode package to CDS or SignedCDS","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/ccprovider.go","lineNumber":296,"sourceCode":"\t\t}\n\t}\n\n\tif cds != nil && scds != nil {\n\t\t// Both were unmarshaled successfully, this is exactly why the approach of\n\t\t// hoping proto fails for bad inputs is fatally flawed.\n\t\tccproviderLogger.Errorf(\"Could not determine chaincode package type, guessing SignedCDS\")\n\t\treturn scds, nil\n\t}\n\n\tif cds != nil {\n\t\treturn cds, nil\n\t}\n\n\tif scds != nil {\n\t\treturn scds, nil\n\t}\n\n\treturn nil, errors.New(\"could not unmarshal chaincode package to CDS or SignedCDS\")\n}\n\n// GetInstalledChaincodes returns a map whose key is the chaincode id and\n// value is the ChaincodeDeploymentSpec struct for that chaincodes that have\n// been installed (but not necessarily instantiated) on the peer by searching\n// the chaincode install path\nfunc GetInstalledChaincodes() (*pb.ChaincodeQueryResponse, error) {\n\tfiles, err := os.ReadDir(chaincodeInstallPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// array to store info for all chaincode entries from LSCC\n\tvar ccInfoArray []*pb.ChaincodeInfo\n\n\tfor _, file := range files {\n\t\t// split at first period as chaincode versions can contain periods while\n\t\t// chaincode names cannot","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/ccprovider.go#L278-L314","documentation":"GetCCPackage attempts to decode a chaincode package buffer first as ChaincodeDeploymentSpec (CDS) and then as SignedChaincodeDeploymentSpec (SignedCDS). If neither protobuf unmarshal succeeds, it concludes the bytes are not a recognizable chaincode package and returns this error.","triggerScenarios":"Calling GetCCPackage with bytes that are neither a CDS nor a SignedCDS — empty buffer, random garbage, an already-tarred install package, or a package format from an incompatible Fabric version.","commonSituations":"Passing the .tar.gz file contents from 'peer chaincode package' directly instead of the packaged CDS bytes; uploading corrupted package over the network; mixing Fabric v1.x package formats across versions.","solutions":["Confirm you are passing raw CDS/SignedCDS protobuf bytes, not a tar package archive","Regenerate the package with the matching Fabric SDK/version and retry","Verify the buffer is not empty or truncated (check byte length before calling)","Check for network/storage corruption if the bytes came from a transfer"],"exampleFix":"// before\nccpack, err := ccprovider.GetCCPackage(tarFileBytes, cifs.GetHasher) // wrong: tar archive\n// after\nccpack, err := ccprovider.GetCCPackage(cdsBytes, cifs.GetHasher) // raw CDS protobuf bytes","handlingStrategy":"validation","validationCode":"func isPlausibleCDS(buf []byte) bool {\n    cds := &pb.ChaincodeDeploymentSpec{}\n    return len(buf) > 0 && proto.Unmarshal(buf, cds) == nil && cds.ChaincodeSpec != nil\n}","typeGuard":"func isCDSBuffer(buf []byte) bool {\n    spec := &pb.ChaincodeDeploymentSpec{}\n    return proto.Unmarshal(buf, spec) == nil && spec.ChaincodeSpec != nil && spec.ChaincodeSpec.ChaincodeId != nil\n}","tryCatchPattern":"ccpack, err := ccprovider.GetCCPackage(buf, hasher)\nif err != nil {\n    if err.Error() == \"could not unmarshal chaincode package to CDS or SignedCDS\" {\n        return fmt.Errorf(\"not a chaincode package (got %d bytes): %w\", len(buf), err)\n    }\n    return err\n}","preventionTips":["Pass raw CDS/SignedCDS bytes, never tar archives or envelopes","Validate byte length and source before calling","Pin SDK/Fabric versions so package formats match","Checksum packages on transfer to detect corruption"],"tags":["hyperledger-fabric","protobuf","unmarshal","chaincode"],"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"}