{"record":{"id":"21ca63c9e5c8fda7","repo":"juicedata/juicefs","slug":"invalid-magic-number-d-expect-d","errorCode":null,"errorMessage":"invalid magic number %d, expect %d","messagePattern":"invalid magic number (.+?), expect (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/backup.go","lineNumber":170,"sourceCode":"\t\treturn err\n\t}\n\treturn f.Footer.Marshal(w)\n}\n\nfunc (f *BakFormat) writeEOS(w io.Writer) error {\n\tif n, err := w.Write(binary.BigEndian.AppendUint32(nil, BakEOS)); err != nil && n != 4 {\n\t\treturn fmt.Errorf(\"failed to write EOS: err %w, write len %d, expect len 4\", err, n)\n\t}\n\treturn nil\n}\n\nfunc (f *BakFormat) ReadFooter(r io.ReadSeeker) (*BakFooter, error) { // nolint:unused\n\tfooter := &BakFooter{}\n\tif err := footer.Unmarshal(r); err != nil {\n\t\treturn nil, err\n\t}\n\tif footer.Msg.Magic != BakMagic {\n\t\treturn nil, fmt.Errorf(\"invalid magic number %d, expect %d\", footer.Msg.Magic, BakMagic)\n\t}\n\tf.Footer = footer\n\treturn footer, nil\n}\n\ntype BakFooter struct {\n\tMsg *pb.Footer\n\tLen uint64\n}\n\nfunc (h *BakFooter) Marshal(w io.Writer) error {\n\tdata, err := proto.Marshal(h.Msg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal footer: %w\", err)\n\t}\n\n\tif n, err := w.Write(data); err != nil && n != len(data) {\n\t\treturn fmt.Errorf(\"failed to write footer data: err %w, write len %d, expect len %d\", err, n, len(data))","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/backup.go#L152-L188","documentation":"ReadFooter validates the backup file's magic number stored in the footer. If the footer's Magic field does not equal BakMagic, the file is not a JuiceFS metadata backup (or is from an incompatible/older format) and reading is refused.","triggerScenarios":"Calling ReadFooter (e.g. via showBakSummary) on a file that is empty, truncated to fewer bytes than the footer, or simply not a JuiceFS backup — the tail bytes read as garbage produce a wrong magic value.","commonSituations":"Running juicefs dump --info / summary against the wrong file; a backup that was truncated or corrupted during transfer; a backup produced by an older format version with a different magic.","solutions":["Confirm the file is a JuiceFS metadata backup produced by juicefs dump (check with `file`/hexdump of the tail)","Regenerate the backup from the metadata engine","Use a JuiceFS version compatible with the backup format version"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check file looks like a JFS backup before parsing\nfi, err := os.Stat(path)\nif err != nil || fi.Size() < 32 {\n    return fmt.Errorf(\"%s is too small to be a JuiceFS backup\", path)\n}","typeGuard":null,"tryCatchPattern":"footer, err := f.ReadFooter(rs)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid magic number\") {\n        return fmt.Errorf(\"not a JuiceFS metadata backup: %w\", err)\n    }\n    return err\n}","preventionTips":["Only run summary/load on files produced by juicefs dump","Verify checksums after transfer","Watch for format-version changes across upgrades"],"tags":["backup","validation","magic-number","format"],"backgroundTag":"invalid-magic-number","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}