{"record":{"id":"91b5649912b1070d","repo":"hyperledger/fabric","slug":"invalid-chaincode-name-q-91b564","errorCode":null,"errorMessage":"invalid chaincode name: %q","messagePattern":"invalid chaincode name: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/sigcdspackage.go","lineNumber":202,"sourceCode":"\t\treturn errors.New(\"uninitialized package\")\n\t}\n\n\tif ccpack.sDepSpec.ChaincodeDeploymentSpec == nil {\n\t\treturn errors.New(\"signed chaincode deployment spec cannot be nil in a package\")\n\t}\n\n\tif ccpack.depSpec == nil {\n\t\treturn errors.New(\"chaincode deployment spec cannot be nil in a package\")\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 := &SignedCDSData{}\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":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/sigcdspackage.go#L184-L220","documentation":"ValidateCC checks that the ChaincodeData name embedded in the package is a printable string. Protobuf can deserialize garbage bytes into odd values, so the library rejects non-printable names. This indicates the package bytes did not decode into a meaningful ChaincodeData.","triggerScenarios":"GetCCPackage -> ValidateCC on a package where ccdata.Name contains non-printable/control characters, typically because the bytes were unmarshaled into the wrong message type.","commonSituations":"Corrupted or truncated package files; packages produced by buggy custom tooling; feeding an unrelated protobuf envelope to the package loader.","solutions":["Repackage the chaincode with a valid, printable chaincode name (letters, digits, dashes)","Check that the package file was not corrupted in transit (compare checksums)","Ensure you are loading a signed CDS package, not another envelope type"],"exampleFix":"// before\nname := \"\\x00bad\\nname\"\n// after\nname := \"mycc\" // printable, valid chaincode name","handlingStrategy":"validation","validationCode":"func validCCName(name string) bool {\n    if name == \"\" { return false }\n    for _, r := range name {\n        if !unicode.IsPrint(r) { return false }\n    }\n    return true\n}","typeGuard":"func isPrintableName(c *pb.ChaincodeData) bool {\n    return c != nil && validCCName(c.Name)\n}","tryCatchPattern":"cd, err := GetCCPackage(buf, idFunc)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid chaincode name\") {\n        return fmt.Errorf(\"package file corrupt; repackage the chaincode: %w\", err)\n    }\n    return err\n}","preventionTips":["Use only [a-zA-Z0-9-] chaincode names","Never edit package bytes after creation","Checksum-verify package files after transfer"],"tags":["chaincode","packaging","fabric","protobuf"],"backgroundTag":"invalid-identifier","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"}