{"record":{"id":"04d6bfe37b6e1ebd","repo":"AlistGo/alist","slug":"failed-to-decode-image-w","errorCode":null,"errorMessage":"failed to decode image: %w","messagePattern":"failed to decode image: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"drivers/local/util.go","lineNumber":127,"sourceCode":"\t}\n\tif outBuffer == nil || outBuffer.Len() == 0 {\n\t\treturn nil, fmt.Errorf(\"ffmpeg-go produced empty buffer for %s\", inputFile)\n\t}\n\n\treturn outBuffer, nil\n}\n\nfunc generateThumbnailWithImagingOptimized(imagePath string, targetWidth int, quality int) (*bytes.Buffer, error) {\n\n\tfile, err := os.Open(imagePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open image: %w\", err)\n\t}\n\tdefer file.Close()\n\n\timg, err := imaging.Decode(file, imaging.AutoOrientation(true))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode image: %w\", err)\n\t}\n\n\tthumbImg := imaging.Resize(img, targetWidth, 0, imaging.Lanczos)\n\timg = nil\n\n\tvar buf bytes.Buffer\n\t// imaging.Encode\n\t// imaging.PNG, imaging.JPEG, imaging.GIF, imaging.BMP, imaging.TIFF\n\toutputFormat := imaging.JPEG\n\tencodeOptions := []imaging.EncodeOption{imaging.JPEGQuality(quality)}\n\n\t// outputFormat := imaging.PNG\n\t// encodeOptions := []imaging.EncodeOption{}\n\n\terr = imaging.Encode(&buf, thumbImg, outputFormat, encodeOptions...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode thumbnail: %w\", err)\n\t}","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/local/util.go#L109-L145","documentation":"imaging.Decode (github.com/disintegration/imaging with AutoOrientation) failed to decode the opened file. It uses Go's image.RegisterFormat-registered decoders, so it natively supports JPEG/PNG/GIF/BMP/TIFF only. The wrapped error is image.ErrFormat ('image: unknown format') for anything else, or a decode error for truncated/corrupt data.","triggerScenarios":"Decoding a WebP, HEIC, AVIF, or SVG file — none are registered by default; decoding a truncated JPEG (download interrupted); decoding a file whose magic bytes are recognized but whose data stream is corrupt.","commonSituations":"The exact scenario that pushes users to enable useFFmpeg: modern phone photos in HEIC/WebP are not decodable by the pure-Go path. Also partially-written files and zero-byte images.","solutions":["Identify the actual format: 'file <path>' — if WebP/HEIC/AVIF, enable the driver's useFFmpeg option so ffmpeg handles decoding","If you must stay pure-Go, register a WebP decoder (e.g. golang.org/x/image/webp) via image.RegisterFormat before imaging.Decode","For corrupt/truncated files, re-obtain the source file"],"exampleFix":"// before: default decoders only (JPEG/PNG/GIF/BMP/TIFF)\nimg, err := imaging.Decode(file, imaging.AutoOrientation(true))\n\n// after: register WebP support once at init, then decode\nimport (\n    \"image\"\n    _ \"golang.org/x/image/webp\"\n)\nfunc init() {\n    image.RegisterFormat(\"webp\", \"RIFF????WEBPVP8\", webp.Decode, webp.DecodeConfig)\n}","handlingStrategy":"fallback","validationCode":"// sniff the format first to decide the decoder route\nfunc decodeWithFallback(path string) (image.Image, error) {\n    f, _ := os.Open(path)\n    defer f.Close()\n    _, format, err := image.DecodeConfig(f)\n    if err != nil {\n        return nil, err // unknown format -> use ffmpeg route\n    }\n    if _, err := f.Seek(0, io.SeekStart); err != nil { return nil, err }\n    return imaging.Decode(f, imaging.AutoOrientation(true))\n}","typeGuard":null,"tryCatchPattern":"if _, err := imaging.Decode(file, imaging.AutoOrientation(true)); err != nil { if errors.Is(err, image.ErrFormat) { switch to resizeImageToBufferWithFFmpegGo } else { return err } }","preventionTips":["Route WebP/HEIC/AVIF files to the ffmpeg path (useFFmpeg) or register x/image/webp","Sniff format with image.DecodeConfig before committing to the pure-Go decoder","Skip thumbnails for formats no decoder supports rather than erroring"],"tags":["image-decoding","thumbnail","format-support","webp","heic","local-driver"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}