{"record":{"id":"1aefcc0c44258298","repo":"hyperledger/fabric","slug":"error-unmarshalling-header","errorCode":null,"errorMessage":"error unmarshalling Header","messagePattern":"error unmarshalling Header","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":95,"sourceCode":"\n// UnmarshalIdentifierHeader unmarshals bytes to an IdentifierHeader\nfunc UnmarshalIdentifierHeader(bytes []byte) (*common.IdentifierHeader, error) {\n\tih := &common.IdentifierHeader{}\n\terr := proto.Unmarshal(bytes, ih)\n\treturn ih, errors.Wrap(err, \"error unmarshalling IdentifierHeader\")\n}\n\nfunc UnmarshalSerializedIdentity(bytes []byte) (*msp.SerializedIdentity, error) {\n\tsid := &msp.SerializedIdentity{}\n\terr := proto.Unmarshal(bytes, sid)\n\treturn sid, errors.Wrap(err, \"error unmarshalling SerializedIdentity\")\n}\n\n// UnmarshalHeader unmarshals bytes to a Header\nfunc UnmarshalHeader(bytes []byte) (*common.Header, error) {\n\thdr := &common.Header{}\n\terr := proto.Unmarshal(bytes, hdr)\n\treturn hdr, errors.Wrap(err, \"error unmarshalling Header\")\n}\n\n// UnmarshalConfigEnvelope unmarshals bytes to a ConfigEnvelope\nfunc UnmarshalConfigEnvelope(bytes []byte) (*common.ConfigEnvelope, error) {\n\tcfg := &common.ConfigEnvelope{}\n\terr := proto.Unmarshal(bytes, cfg)\n\treturn cfg, errors.Wrap(err, \"error unmarshalling ConfigEnvelope\")\n}\n\n// UnmarshalChaincodeHeaderExtension unmarshals bytes to a ChaincodeHeaderExtension\nfunc UnmarshalChaincodeHeaderExtension(hdrExtension []byte) (*peer.ChaincodeHeaderExtension, error) {\n\tchaincodeHdrExt := &peer.ChaincodeHeaderExtension{}\n\terr := proto.Unmarshal(hdrExtension, chaincodeHdrExt)\n\treturn chaincodeHdrExt, errors.Wrap(err, \"error unmarshalling ChaincodeHeaderExtension\")\n}\n\n// UnmarshalProposalResponse unmarshals bytes to a ProposalResponse\nfunc UnmarshalProposalResponse(prBytes []byte) (*peer.ProposalResponse, error) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L77-L113","documentation":"Returned by protoutil.UnmarshalHeader when proto.Unmarshal cannot decode the bytes into a common.Header message. The library wraps the protobuf error so the failing message type is clear. It means the payload is not a validly encoded Header (wrong type, truncated, or corrupted).","triggerScenarios":"Calling UnmarshalHeader on signature/payload header bytes that are empty, truncated, belong to a different message type (e.g. a SerializedIdentity), or were produced with mismatched protobuf definitions; invoked from CheckACL, getSignedData, UnpackProposal, and proposal validation paths.","commonSituations":"Submitting hand-crafted proposals with malformed headers; ACL checks on corrupted transactions read from a block; channel header/signature header swapped; SDK/peer protobuf version drift.","solutions":["Confirm the bytes are exactly the Header portion (ChannelHeader+SignatureHeader) of the payload, not the whole payload or envelope.","Validate non-empty, non-truncated input before calling; log length and first bytes on failure.","Regenerate the proposal/transaction with a matching Fabric SDK/peer version.","Check that channel header and signature header byte slices were not concatenated or swapped.","Wrap the error with request context and reject the transaction/proposal cleanly."],"exampleFix":"// before\nhdr, _ := protoutil.UnmarshalHeader(payloadBytes) // wrong slice: whole payload\n// after\nhdr, err := protoutil.UnmarshalHeader(payload.Header)\nif err != nil {\n    return fmt.Errorf(\"invalid payload header: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func validHeader(b []byte) bool {\n    hdr := &common.Header{}\n    return len(b) > 0 && proto.Unmarshal(b, hdr) == nil && hdr.ChannelHeader != nil\n}","typeGuard":"func isHeader(v any) bool {\n    _, ok := v.(*common.Header)\n    return ok\n}","tryCatchPattern":"hdr, err := protoutil.UnmarshalHeader(b)\nif err != nil {\n    return nil, fmt.Errorf(\"malformed header (%d bytes): %w\", len(b), err)\n}","preventionTips":["Pass only payload.Header bytes, not whole payloads or envelopes","Validate parent payload first with protoutil.UnmarshalPayload","Log byte length on failure for diagnosis","Keep SDK/peer protobuf definitions in sync"],"tags":["fabric","protobuf","unmarshal","header"],"backgroundTag":"protobuf-unmarshal-failed","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"}