{"record":{"id":"34273b892a302ffc","repo":"hyperledger/fabric","slug":"invalid-type-of-envelope-for-chaincode-package","errorCode":null,"errorMessage":"invalid type of envelope for chaincode package","messagePattern":"invalid type of envelope for chaincode package","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/sigcdspackage.go","lineNumber":235,"sourceCode":"\t}\n\n\treturn nil\n}\n\n// InitFromBuffer sets the buffer if valid and returns ChaincodeData\nfunc (ccpack *SignedCDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {\n\tenv := &common.Envelope{}\n\terr := proto.Unmarshal(buf, env)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to unmarshal envelope from bytes\")\n\t}\n\tcHdr, sDepSpec, err := ccpackage.ExtractSignedCCDepSpec(env)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif cHdr.Type != int32(common.HeaderType_CHAINCODE_PACKAGE) {\n\t\treturn nil, errors.New(\"invalid type of envelope for chaincode package\")\n\t}\n\n\tdepSpec := &pb.ChaincodeDeploymentSpec{}\n\terr = proto.Unmarshal(sDepSpec.ChaincodeDeploymentSpec, depSpec)\n\tif err != nil {\n\t\treturn nil, errors.New(\"error getting deployment spec\")\n\t}\n\n\tdatabytes, id, data, err := ccpack.getCDSData(sDepSpec)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tccpack.buf = buf\n\tccpack.sDepSpec = sDepSpec\n\tccpack.depSpec = depSpec\n\tccpack.env = env\n\tccpack.data = data","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/sigcdspackage.go#L217-L253","documentation":"InitFromBuffer extracts a signed CDS from the envelope and then verifies the channel header type equals HeaderType_CHAINCODE_PACKAGE. An envelope of any other type is rejected, since only chaincode-package envelopes carry signed deployment specs.","triggerScenarios":"InitFromBuffer called with a valid protobuf Envelope whose header type is not CHAINCODE_PACKAGE (e.g. a transaction, config, or ESCC/VSCC envelope).","commonSituations":"Accidentally passing a transaction envelope or another artifact file to the package loader; confusing signed package files with other fabric envelope files on disk.","solutions":["Load the file produced by `peer chaincode signpackage` — its envelope type is CHAINCODE_PACKAGE","Verify you are not passing a transaction/config envelope to GetCCPackage","Check for mixed-up files in the deployment artifacts directory"],"exampleFix":"// before\nenvBytes := readTxEnvelopeBytes() // HeaderType_TRANSACTION\n// after\nenvBytes := readSignedPackageBytes() // HeaderType_CHAINCODE_PACKAGE","handlingStrategy":"validation","validationCode":"func isChaincodePackageEnv(env *common.Envelope) (bool, error) {\n    p := &common.Payload{}\n    if err := proto.Unmarshal(env.Payload, p); err != nil { return false, err }\n    h := &common.Header{}\n    if err := proto.Unmarshal(p.Header, h); err != nil { return false, err }\n    return h.ChannelHeader != nil && h.ChannelHeader.Type == int32(common.HeaderType_CHAINCODE_PACKAGE), nil\n}","typeGuard":"func isChaincodePackageType(t int32) bool { return t == int32(common.HeaderType_CHAINCODE_PACKAGE) }","tryCatchPattern":"cd, err := GetCCPackage(buf, idFunc)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid type of envelope\") {\n        return fmt.Errorf(\"wrong artifact: expected a CHAINCODE_PACKAGE envelope: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep signed packages in a dedicated directory separate from tx envelopes","Label artifacts clearly (e.g. .signed.pack vs .tx)","Inspect the header type before loading if the source is uncertain"],"tags":["chaincode","fabric","envelope","validation"],"backgroundTag":"wrong-message-type","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}