{"record":{"id":"20ea51ab6a350f60","repo":"hyperledger/fabric","slug":"invalid-chaincode-data-v-v","errorCode":null,"errorMessage":"invalid chaincode data %v (%v)","messagePattern":"invalid chaincode data (.+?) \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/cdspackage.go","lineNumber":163,"sourceCode":"\t\treturn errors.New(\"uninitialized package\")\n\t}\n\n\tif ccpack.data == nil {\n\t\treturn errors.New(\"nil data\")\n\t}\n\n\t// This is a hack. LSCC expects a specific LSCC error when names are invalid so it\n\t// has its own validation code. We can't use that error because of import cycles.\n\t// Unfortunately, we also need to check if what have makes some sort of sense as\n\t// protobuf will gladly deserialize garbage and there are paths where we assume that\n\t// a successful unmarshal means everything works but, if it fails, we try to unmarshal\n\t// into something different.\n\tif !isPrintable(ccdata.Name) {\n\t\treturn fmt.Errorf(\"invalid chaincode name: %q\", ccdata.Name)\n\t}\n\n\tif ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {\n\t\treturn fmt.Errorf(\"invalid chaincode data %v (%v)\", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)\n\t}\n\n\totherdata := &CDSData{}\n\terr := proto.Unmarshal(ccdata.Data, otherdata)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !proto.Equal(ccpack.data, otherdata) {\n\t\treturn errors.New(\"data mismatch\")\n\t}\n\n\treturn nil\n}\n\n// InitFromBuffer sets the buffer if valid and returns ChaincodeData\nfunc (ccpack *CDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {\n\tdepSpec := &pb.ChaincodeDeploymentSpec{}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/cdspackage.go#L145-L181","documentation":"ValidateCC compares the ChaincodeData name/version against the package's depSpec ChaincodeId and, if they differ, reports 'invalid chaincode data'. It also unmarshals ccdata.Data into CDSData and compares with the package's computed data; any inconsistency between the metadata and the actual package contents triggers this error.","triggerScenarios":"ChaincodeData supplied to ValidateCC has Name or Version not matching depSpec.ChaincodeSpec.ChaincodeId, or its serialized Data does not match the package's computed CDSData hash content.","commonSituations":"Chaincode installed under a different name/version than referenced; mixing data from two packages; corrupted Data blob after unmarshal of garbage protobuf.","solutions":["Ensure the ChaincodeData comes from the same package — recompute it via InitFromBuffer/InitFromPath rather than hand-building","Align the name/version used at install with the CDS ChaincodeId","Reinstall the chaincode package if its data hash does not match the metadata","Check for corruption if Data unmarshals but mismatches"],"exampleFix":"// before\nccdata := &ChaincodeData{Name: \"othercc\", Version: \"1.0\"}\nccpack.ValidateCC(ccdata) // mismatch vs depSpec mycc:1.0\n// after\nccdata := ccpack.GetChaincodeData() // derive data from the same package\nccpack.ValidateCC(ccdata)","handlingStrategy":"validation","validationCode":"// confirm data and spec agree before validation\nif ccdata.Name != depSpec.ChaincodeSpec.ChaincodeId.Name ||\n   ccdata.Version != depSpec.ChaincodeSpec.ChaincodeId.Version {\n    return fmt.Errorf(\"chaincode data %s:%s does not match package %s:%s\",\n        ccdata.Name, ccdata.Version,\n        depSpec.ChaincodeSpec.ChaincodeId.Name, depSpec.ChaincodeSpec.ChaincodeId.Version)\n}","typeGuard":"func dataMatchesSpec(ccdata *ccprovider.ChaincodeData, spec *pb.ChaincodeSpec) bool {\n    return ccdata != nil && spec != nil &&\n        ccdata.Name == spec.ChaincodeId.Name && ccdata.Version == spec.ChaincodeId.Version\n}","tryCatchPattern":"if err := ccpack.ValidateCC(ccdata); err != nil {\n    if strings.HasPrefix(err.Error(), \"invalid chaincode data\") {\n        // re-derive data from the package instead of failing permanently\n        fresh, ierr := ccpack.InitFromBuffer(originalBuf)\n        if ierr == nil { ccdata = fresh }\n    }\n    return err\n}","preventionTips":["Always derive ChaincodeData from the same package via GetChaincodeData/InitFromBuffer","Keep install-time name/version identical to the CDS ChaincodeId","Never mix metadata from one package with bytes from another","Version-pin chaincode packages across peers"],"tags":["hyperledger-fabric","chaincode","validation","mismatch"],"backgroundTag":"chaincode-data-mismatch","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"}