{"record":{"id":"0f1bc212b47af104","repo":"FiloSottile/age","slug":"failed-to-re-serialize-header-w","errorCode":null,"errorMessage":"failed to re-serialize header: %w","messagePattern":"failed to re-serialize header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/inspect/inspect.go","lineNumber":57,"sourceCode":"\ttr := &trackReader{r: r}\n\tbr := bufio.NewReader(tr)\n\tconst maxWhitespace = 1024\n\tstart, _ := br.Peek(maxWhitespace + len(armor.Header))\n\tif strings.HasPrefix(string(bytes.TrimSpace(start)), armor.Header) {\n\t\tr = armor.NewReader(br)\n\t\tdata.Armor = true\n\t} else {\n\t\tr = br\n\t}\n\n\thdr, rest, err := format.Parse(r)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read header: %w\", err)\n\t}\n\n\tbuf := &bytes.Buffer{}\n\tif err := hdr.Marshal(buf); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to re-serialize header: %w\", err)\n\t}\n\tdata.Sizes.Header = int64(buf.Len())\n\n\tfor _, s := range hdr.Recipients {\n\t\tdata.StanzaTypes = append(data.StanzaTypes, s.Type)\n\t\tswitch s.Type {\n\t\tcase \"X25519\", \"ssh-rsa\", \"ssh-ed25519\", \"p256tag\", \"piv-p256\":\n\t\t\tdata.Postquantum = \"no\"\n\t\tcase \"mlkem768x25519\", \"scrypt\", \"mlkem768p256tag\":\n\t\t\t// Keep \"yes\".\n\t\tdefault:\n\t\t\tif data.Postquantum != \"no\" {\n\t\t\t\tdata.Postquantum = \"unknown\"\n\t\t\t}\n\t\t}\n\t}\n\n\t// If fileSize is not provided, or if it's the size of the armored file","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/FiloSottile/age/blob/b74dce4cdbe35b5e5f66c06d9612b72f89028758/internal/inspect/inspect.go#L39-L75","documentation":"After parsing, Inspect re-serializes the header with hdr.Marshal into a bytes.Buffer to measure its size. Writes to a bytes.Buffer only fail on OOM, so this is nearly impossible in practice; the wrap exists for completeness of the error path.","triggerScenarios":"hdr.Marshal(buf) returns non-nil while Inspect measures data.Sizes.Header — effectively only under memory exhaustion or a custom Marshal failure.","commonSituations":"Extremely large headers with the maximum number of recipient stanzas on memory-constrained systems; essentially never in normal use.","solutions":["Check available memory if processing pathological inputs","Reduce the number of recipient stanzas when generating files","Report a bug if this reproduces with normal files — it indicates a Marshal implementation issue"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Marshal targets a bytes.Buffer; nothing useful can be validated beforehand.","typeGuard":"if err != nil { /* treat as OOM/systemic; retry or abort */ }","tryCatchPattern":"var buf bytes.Buffer\nif err := hdr.Marshal(&buf); err != nil {\n    return nil, fmt.Errorf(\"header re-serialization failed (memory?): %w\", err)\n}","preventionTips":["Avoid pathological headers with thousands of stanzas","Retry once on failure — transient memory pressure is the only realistic cause","Report persistent occurrences as library bugs"],"tags":["inspect","serialization","memory"],"backgroundTag":"buffer-write-failed","analyzedSha":"b74dce4cdbe35b5e5f66c06d9612b72f89028758","analyzedAt":"2026-08-31T23:59:31.627Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}