{"record":{"id":"3fdaf207d0a992c2","repo":"siyuan-note/siyuan","slug":"errinvalid","errorCode":"ErrInvalid","errorMessage":"heic: invalid file","messagePattern":"heic: invalid file","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/heif/internal/h265heic/isobmff.go","lineNumber":28,"sourceCode":"\tmaxContainerBytes = 32 << 20\n\tmaxMetadataBytes  = 16 << 20\n\tmaxItems          = 4096\n\tmaxProperties     = 4096\n\tmaxItemExtents    = 16384\n\tmaxItemReferences = 16384\n\tmaxItemProperties = 16384\n\tmaxItemDataBytes  = 32 << 20\n\tmaxParameterSets  = 64\n\tmaxParameterBytes = 1 << 20\n\tmaxNALUnits       = 65536\n\tmaxNALBytes       = 32 << 20\n\tmaxMetadataBoxes  = 65536\n\tmaxTopLevelBoxes  = 4096\n)\n\n// ErrInvalid is returned when a file is not a HEIF, or is malformed past the\n// point where anything can be decoded from it.\nvar ErrInvalid = errors.New(\"heic: invalid file\")\n\ntype reader struct {\n\tb   []byte\n\ti   int\n\terr bool\n}\n\nfunc (r *reader) remaining() int {\n\tif r.err {\n\t\treturn 0\n\t}\n\n\treturn len(r.b) - r.i\n}\n\nfunc (r *reader) fail() {\n\tr.err = true\n\tr.i = len(r.b)","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/heif/internal/h265heic/isobmff.go#L10-L46","documentation":"ErrInvalid is the sentinel error of the h265heic isobmff parser, declared in kernel/heif/internal/h265heic/isobmff.go:28. It is returned when a byte stream is not a HEIF/HEIC container at all, or is so malformed that nothing can be decoded from it — box parsing exceeds the hard limits (65536 metadata boxes, 4096 top-level boxes) or the file structure is unreadable. It signals 'give up: no image data can be extracted from this input'.","triggerScenarios":"Parsing a file whose magic bytes are not a valid ISOBMFF/HEIF container; a truncated or corrupted .heic file; a file with more than 4096 top-level boxes or 65536 metadata boxes; feeding a JPEG/PNG or arbitrary bytes to the HEIC parser.","commonSituations":"Users paste an asset that was renamed to .heic but is actually another format; downloads truncated mid-transfer; fuzzed or intentionally malicious files; old phone exports with nonstandard box layouts.","solutions":["Verify the file is a genuine HEIC container (bytes start with 'ftyp' box with heic/heix/mif1 brand) before parsing","Re-download or re-export the image; a truncated file cannot be repaired by the parser","Convert the image to HEIC with a known-good tool (e.g. libheif/ffmpeg) and retry","Check file size — a 0-byte or few-byte file is guaranteed to fail"],"exampleFix":"// before\nret, err := h265heic.Parse(data)\n// after\nif len(data) < 12 || string(data[4:8]) != \"ftyp\" {\n    return fmt.Errorf(\"not a HEIC container\")\n}\nret, err := h265heic.Parse(data)","handlingStrategy":"validation","validationCode":"func looksLikeHEIC(b []byte) bool {\n    return len(b) >= 12 && string(b[4:8]) == \"ftyp\"\n}","typeGuard":"func isHEICBrand(b []byte) bool {\n    if len(b) < 12 || string(b[4:8]) != \"ftyp\" {\n        return false\n    }\n    brand := string(b[8:12])\n    return brand == \"heic\" || brand == \"heix\" || brand == \"mif1\" || brand == \"hevc\"\n}","tryCatchPattern":null,"preventionTips":["Sniff the ftyp box and brand before parsing","Check for minimum viable file size before parsing","Re-download truncated files instead of retrying parses","Quarantine files that fail parsing to avoid repeated failures"],"tags":["go","image-parsing","heic","malformed-input"],"backgroundTag":"invalid-argument-format","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}