{"id":"d04097f288a49bed","repo":"gohugoio/hugo","slug":"decoded-avif-buffer-size-d-is-not-a-multiple-of-f","errorCode":null,"errorMessage":"decoded AVIF buffer size %d is not a multiple of frame size %d","messagePattern":"decoded AVIF buffer size (.+?) is not a multiple of frame size (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/avif.go","lineNumber":162,"sourceCode":"\t\t}\n\t}\n\n\tif len(out.Data.Params.FrameDurations) > 0 {\n\t\timg := &AnimatedImage{\n\t\t\tframeDurations:          out.Data.Params.FrameDurations,\n\t\t\tloopCount:               avifLoopCountToGo(out.Data.Params.LoopCount),\n\t\t\tdepth:                   depth,\n\t\t\tcolorPrimaries:          out.Data.Params.ColorPrimaries,\n\t\t\ttransferCharacteristics: out.Data.Params.TransferCharacteristics,\n\t\t\tmatrixCoefficients:      out.Data.Params.MatrixCoefficients,\n\t\t\tmaxCLL:                  out.Data.Params.MaxCLL,\n\t\t\tmaxPALL:                 out.Data.Params.MaxPALL,\n\t\t}\n\n\t\tframeSize := stride * h\n\t\tpixLen := len(destination.Bytes())\n\t\tif frameSize == 0 || pixLen%frameSize != 0 {\n\t\t\treturn nil, fmt.Errorf(\"decoded AVIF buffer size %d is not a multiple of frame size %d\", pixLen, frameSize)\n\t\t}\n\t\tframeCount := pixLen / frameSize\n\t\tif frameCount != len(out.Data.Params.FrameDurations) {\n\t\t\treturn nil, fmt.Errorf(\"decoded AVIF frame count %d does not match frame durations %d\", frameCount, len(out.Data.Params.FrameDurations))\n\t\t}\n\t\tframes := make([]image.Image, frameCount)\n\t\tfor i := range frames {\n\t\t\tframeBytes := destination.Bytes()[i*frameSize : (i+1)*frameSize]\n\t\t\tif isHDR {\n\t\t\t\t// NRGBA64 for HDR - libavif returns non-premultiplied alpha.\n\t\t\t\tframeImg := &image.NRGBA64{\n\t\t\t\t\tPix:    frameBytes,\n\t\t\t\t\tStride: stride,\n\t\t\t\t\tRect:   image.Rect(0, 0, w, h),\n\t\t\t\t}\n\t\t\t\tframes[i] = frameImg\n\t\t\t} else {\n\t\t\t\t// NRGBA - libavif returns non-premultiplied alpha.","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/warpc/avif.go#L144-L180","documentation":"Raised in AvifCodec.Decode (internal/warpc/avif.go:162) when decoding an animated AVIF. The decoder computes frameSize = stride * height and expects the blob returned by the WASM libavif module to contain an exact whole number of frames; if the buffer length isn't a multiple of the frame size (or frame size is 0), the pixel data can't be split into frames and Hugo aborts the decode.","triggerScenarios":"Decoding an animated AVIF (Params.FrameDurations non-empty) where the raw pixel blob streamed back from the WASM module has a length not divisible by stride*height — indicating a truncated blob transfer, an HDR/8-bit depth mismatch in stride accounting, or a corrupt animation.","commonSituations":"Corrupted/truncated animated AVIF files; animated AVIFs with unusual per-frame geometry or produced by nonstandard encoders; edge cases in HDR (10/12-bit) animated AVIFs where 16-bit output changes buffer size expectations.","solutions":["Re-encode the animated AVIF with a standard tool (avifenc/ffmpeg) and constant frame dimensions.","Verify the file plays correctly in a browser to rule out corruption.","As a workaround, convert the asset to animated WebP or GIF for Hugo processing.","If reproducible with a valid file, report it to Hugo with the file attached — it indicates a decoder protocol bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"img, err := decodeAVIF(buf)\nif err != nil {\n    // indicates a truncated/corrupt AVIF or a decoder bug — surface, don't mask\n    return fmt.Errorf(\"corrupt AVIF %s: %w\", path, err)\n}","preventionTips":["Verify AVIF files aren't truncated (checksum or re-download) before feeding them to the pipeline","Keep the WASM decoder (warpc runtime) up to date; buffer-size mismatch usually means version skew or corruption","Fail the single asset with a clear filename in the error rather than aborting silently"],"tags":["hugo","avif","animated-image","image-processing","wasm","warpc"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}