{"record":{"id":"df5a9ebb639a9209","repo":"gohugoio/hugo","slug":"webppictureinit-failed-n","errorCode":null,"errorMessage":"WebPPictureInit failed\\n","messagePattern":"WebPPictureInit failed\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/genwebp/webp.c","lineNumber":117,"sourceCode":"} InputMessage;\n\ntypedef struct\n{\n    Header header;\n    InputData data;\n\n} OutputMessage;\n\n#define MAX_LINE_LENGTH 4096\n\nstatic uint8_t *encodeNRGBA(WebPConfig *config, const uint8_t *rgba, int width, int height, int stride, size_t *output_size)\n{\n    WebPPicture pic;\n    WebPMemoryWriter wrt;\n    int ok;\n    if (!WebPPictureInit(&pic))\n    {\n        fprintf(stderr, \"WebPPictureInit failed\\n\");\n        return NULL;\n    }\n\n    pic.use_argb = 1;\n    pic.width = width;\n    pic.height = height;\n    pic.writer = WebPMemoryWrite;\n    pic.custom_ptr = &wrt;\n    WebPMemoryWriterInit(&wrt);\n    ok = WebPPictureImportRGBA(&pic, rgba, stride);\n    if (ok)\n    {\n        ok = WebPEncode(config, &pic);\n        if (!ok)\n        {\n            fprintf(stderr, \"WebPEncode failed: %d (%s)\\n\", pic.error_code, kErrorMessages[pic.error_code]);\n        }\n    }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/warpc/genwebp/webp.c#L99-L135","documentation":"Printed by genwebp's encodeNRGBA (webp.c:117) when WebPPictureInit(&pic) returns false. WebPPictureInit zeroes and sets up a WebPPicture struct and should essentially never fail in a correctly built libwebp; failure indicates an ABI mismatch (the C binary was built against a different libwebp header version than the shared library it loaded), a corrupted WebPPicture pointer, or a severely memory-starved process. The function returns NULL and the caller surfaces 'Error encoding NRGBA to WebP' to the host.","triggerScenarios":"genwebp was built/linked against one libwebp version but at runtime resolves a different version (e.g. system libwebp updated underneath the Hugo binary), the WebPPicture struct layout differs between compile-time headers and runtime library, or memory allocation inside libwebp failed during init.","commonSituations":"Hugo binary moved between machines with incompatible libwebp, a distro upgrade replaced libwebp without rebuilding Hugo's C workers, dynamic linking picks up LD_LIBRARY_PATH override, or a container image layered an incompatible libwebp on top of the Hugo base image.","solutions":["Rebuild the Hugo binary (and its bundled genwebp) from source against the libwebp now present at runtime, or pin libwebp to the version Hugo was built with.","Run `ldd` on the genwebp executable to confirm which libwebp it resolves and that the path matches the build-time expectation.","If shipping a static build, ensure libwebp is statically linked to remove the runtime mismatch class entirely.","In containers, pin the libwebp package version and rebuild the image when bumping it.","Free memory / raise cgroup limits if the box is genuinely OOM."],"exampleFix":"# before: system libwebp updated, Hugo's bundled worker now mismatches\n$ hugo build  # WebPPictureInit failed at runtime\n\n# after: rebuild genwebp against the current libwebp, or link statically\ngo build -tags netgo -ldflags '-linkmode external' ./...\n# or in the Hugo Makefile / build script:\nCGO_LDFLAGS=\"-static\" go build","handlingStrategy":"validation","validationCode":"// In the host: verify the genwebp binary resolves the expected libwebp before use.\nfunc checkLibwebp(ctx context.Context, bin string) error {\n    out, err := exec.CommandContext(ctx, \"ldd\", bin).CombinedOutput()\n    if err != nil { return err }\n    if !bytes.Contains(out, []byte(\"libwebp\")) {\n        return fmt.Errorf(\"genwebp does not link libwebp as expected\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship genwebp with libwebp statically linked to remove the runtime-mismatch class.","Pin the libwebp package version in deployment images and rebuild when bumping.","Run `ldd` on the worker binary in CI to assert the resolved libwebp path.","Treat WebPPictureInit failure as fatal and surface a clear error rather than retrying on the same binary."],"tags":["webp","libwebp","abi","encoding","linkage"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}