{"record":{"id":"017b7ed6baa2b5ce","repo":"hyperledger/fabric","slug":"data-mismatch","errorCode":null,"errorMessage":"data mismatch","messagePattern":"data mismatch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/cdspackage.go","lineNumber":173,"sourceCode":"\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{}\n\terr := proto.Unmarshal(buf, depSpec)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to unmarshal deployment spec from bytes\")\n\t}\n\n\tdatabytes, id, data, err := ccpack.getCDSData(depSpec)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/cdspackage.go#L155-L191","documentation":"As its final check, ValidateCC unmarshals ccdata.Data into a fresh CDSData and requires it to be proto.Equal to the package's stored data. 'data mismatch' means the serialized chaincode data does not equal the data computed from the deployment spec, indicating tampered, stale, or corrupted ChaincodeData.","triggerScenarios":"ccdata.Data was produced from a different CDS than the package's depSpec — e.g. chaincode code changed after data was computed, metadata from one install paired with a package from another, or bytes corrupted in storage.","commonSituations":"Rebuilding a chaincode binary without reinstalling (hash changes); swapping package files while reusing old ChaincodeData; version-skew between peers.","solutions":["Regenerate ChaincodeData from the current package via InitFromBuffer/InitFromPath","Reinstall the chaincode so stored data matches the deployment spec","Verify the chaincode source/binaries were not modified after packaging","Ensure all peers use the same package bytes for the same name:version"],"exampleFix":"// before\nstaleCCData.Data = oldDataBytes // from previous build\n// after\nccdata, err := ccpack.InitFromBuffer(currentBuf) // recomputed matching data","handlingStrategy":"validation","validationCode":"// verify data integrity before validate\nother := &ccprovider.CDSData{}\nif err := proto.Unmarshal(ccdata.Data, other); err != nil {\n    return fmt.Errorf(\"corrupt chaincode data blob: %w\", err)\n}\n// rebuild expected data from the same CDS to compare\n_, _, expected, err := computeCDSData(depSpec)\nif err != nil { return err }\nif !proto.Equal(expected, other) {\n    return errors.New(\"stale or tampered chaincode data; reinstall required\")\n}","typeGuard":null,"tryCatchPattern":"if err := ccpack.ValidateCC(ccdata); err != nil {\n    if err.Error() == \"data mismatch\" {\n        // force repackage/reinstall path\n        return fmt.Errorf(\"chaincode data does not match package, reinstall: %w\", err)\n    }\n    return err\n}","preventionTips":["Recompute ChaincodeData whenever the chaincode binary is rebuilt","Treat package files as immutable after install","Verify checksums of chaincodes directories during peer sync","Roll coordinated redeploys so all peers hold the same package bytes"],"tags":["hyperledger-fabric","chaincode","integrity","hash-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"}