{"record":{"id":"3614e039aff9b2f5","repo":"gohugoio/hugo","slug":"webppictureimportrgba-failed-n","errorCode":null,"errorMessage":"WebPPictureImportRGBA failed\\n","messagePattern":"WebPPictureImportRGBA failed\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/genwebp/webp.c","lineNumber":235,"sourceCode":"\n    for (int i = 0; i < params.frameCount; i++)\n    {\n        WebPPicture pic;\n        if (!WebPPictureInit(&pic))\n        {\n            fprintf(stderr, \"WebPPictureInit failed\\n\");\n            WebPAnimEncoderDelete(enc);\n            return NULL;\n        }\n        pic.use_argb = 1;\n        pic.width = params.width;\n        pic.height = params.height;\n\n        const uint8_t *frame_rgba = all_frames_data + i * frame_rgba_size;\n\n        if (!WebPPictureImportRGBA(&pic, frame_rgba, params.stride))\n        {\n            fprintf(stderr, \"WebPPictureImportRGBA failed\\n\");\n            WebPPictureFree(&pic);\n            WebPAnimEncoderDelete(enc);\n            return NULL;\n        }\n\n        if (!WebPAnimEncoderAdd(enc, &pic, timestamp, config))\n        {\n            fprintf(stderr, \"WebPAnimEncoderAdd failed\\n\");\n            WebPPictureFree(&pic);\n            WebPAnimEncoderDelete(enc);\n            return NULL;\n        }\n        timestamp += params.frameDurations[i];\n        WebPPictureFree(&pic);\n    }\n\n    if (!WebPAnimEncoderAdd(enc, NULL, timestamp, config))\n    {","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/warpc/genwebp/webp.c#L217-L253","documentation":"Printed inside genwebp's encodeNRGBAAnimated loop (webp.c:235) when WebPPictureImportRGBA fails for a frame. Unlike the static path (826) this print does not include the error_code, but the cause class is the same: stride < width*4, dimensions over WebP's limit, or a frame buffer that is too short. The worker frees the picture, deletes the anim encoder, and returns NULL.","triggerScenarios":"params.stride does not equal params.width*4, frame_rgba_size (params.stride*params.height) exceeds the actual remaining bytes in all_frames_data for a given frame index, or width/height drift between frames (the encoder assumes a fixed canvas size).","commonSituations":"Animated source decoded with a stride that does not match what the Go host sends in params.stride, frame_count mismatch so frame_index*frame_rgba_size runs past the buffer end, or a canvas-size change between decode and encode that was not propagated to params.","solutions":["Assert on the Go side that len(all_frames_data) == params.stride*params.height*params.frameCount before invoking the animated encoder.","Pin params.stride = params.width*4 and verify each decoded frame is laid out at exactly that stride.","Confirm params.frameCount matches the number of frames actually packed into all_frames_data.","Compare the canvas dimensions used for decoding against those sent for encoding — they must be identical.","Re-decode the source if any frame's stride looks inconsistent."],"exampleFix":"// before: stride mismatch between decoder output and encoder params\nparams.Stride = w * 3 // wrong for RGBA\nenc.Encode(params, frames)\n\n// after\nparams.Stride = w * 4\nif len(frames) != params.Stride*h*params.FrameCount {\n    return fmt.Errorf(\"frame buffer %d != expected %d\", len(frames), params.Stride*h*params.FrameCount)\n}\nenc.Encode(params, frames)","handlingStrategy":"validation","validationCode":"func validateAnimFrameBuffer(pix []byte, w, h, stride, frameCount int) error {\n    if stride != w*4 { return fmt.Errorf(\"stride %d != width*4 %d\", stride, w*4) }\n    need := stride * h * frameCount\n    if len(pix) < need { return fmt.Errorf(\"buffer %d < need %d\", len(pix), need) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin stride = width*4 for animated RGBA and pass it consistently to decode and encode.","Verify len(pix) >= stride*height*frameCount before sending.","Ensure params.frameCount equals the number of frames actually packed into pix.","Keep canvas dimensions identical between decode and encode."],"tags":["webp","animation","stride","encoding","frame-buffer"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}