{"record":{"id":"484c249e9bfc9096","repo":"hyperledger/fabric","slug":"invalid-chaincode-name-q","errorCode":null,"errorMessage":"invalid chaincode name: %q","messagePattern":"invalid chaincode name: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/cdspackage.go","lineNumber":159,"sourceCode":"// ValidateCC returns error if the chaincode is not found or if its not a\n// ChaincodeDeploymentSpec\nfunc (ccpack *CDSPackage) ValidateCC(ccdata *ChaincodeData) error {\n\tif ccpack.depSpec == nil {\n\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}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/cdspackage.go#L141-L177","documentation":"ValidateCC rejects ChaincodeData whose Name contains non-printable characters using this error. Because protobuf will happily deserialize garbage, the package layer sanity-checks the name before LSCC sees it; non-printable names indicate corrupted or fabricated chaincode data.","triggerScenarios":"Calling ValidateCC (directly or via GetCCPackage/InitFromPath) with a ChaincodeData whose Name field contains non-printable/control characters — corrupt protobuf bytes deserialized as garbage, or malicious input.","commonSituations":"Corrupted package files on disk; an attacker-supplied or fuzzed package buffer; string mangled by encoding issues before packaging.","solutions":["Sanitize the chaincode name before packaging — allow only printable, valid chaincode-name characters","Regenerate/reinstall the package from trusted source since data is likely corrupted","Verify the bytes were not mangled by encoding/transfer issues","Inspect the quoted name (%q) in the error to identify the corruption source"],"exampleFix":"// before\nname := \"my\\x00cc\" // control char embedded\nccdata.Name = name\n// after\nif !isPrintable(name) { return fmt.Errorf(\"invalid chaincode name %q\", name) }\nccdata.Name = \"mycc\"","handlingStrategy":"validation","validationCode":"func validChaincodeName(name string) bool {\n    if name == \"\" { return false }\n    for _, r := range name {\n        if r < 0x20 || r == 0x7f { return false } // non-printable\n    }\n    return true\n}","typeGuard":"func isPrintableName(ccdata *ccprovider.ChaincodeData) bool {\n    return ccdata != nil && validChaincodeName(ccdata.Name)\n}","tryCatchPattern":"if err := ccpack.ValidateCC(ccdata); err != nil {\n    if strings.HasPrefix(err.Error(), \"invalid chaincode name\") {\n        return fmt.Errorf(\"rejecting package: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate user-supplied chaincode names (alnum/dash) before packaging","Checksum package files to detect corruption early","Never build ChaincodeData from untrusted raw bytes without sanitizing","Fuzz/validate input paths that deserialize external buffers"],"tags":["hyperledger-fabric","chaincode","validation","sanitization"],"backgroundTag":"invalid-chaincode-name","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"}