{"record":{"id":"ccf7f1b463376f3f","repo":"d2phap/ImageGlass","slug":"failed-webpdecode-with-error-result","errorCode":null,"errorMessage":"Failed WebPDecode with error {result}","messagePattern":"Failed WebPDecode with error (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"v9/Components/ImageGlass.WebP/WebPWrapper.cs","lineNumber":208,"sourceCode":"            {\n                config.output.colorspace = WEBP_CSP_MODE.MODE_BGR;\n                bmp = new Bitmap(config.input.Width, config.input.Height, PixelFormat.Format24bppRgb);\n            }\n            bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);\n\n            // Specify the output format\n            config.output.u.RGBA.rgba = bmpData.Scan0;\n            config.output.u.RGBA.stride = bmpData.Stride;\n            config.output.u.RGBA.size = (UIntPtr)(bmp.Height * bmpData.Stride);\n            config.output.height = bmp.Height;\n            config.output.width = bmp.Width;\n            config.output.is_external_memory = 1;\n\n            // Decode\n            result = LibWebp.WebPDecode(ptrRawWebP, rawWebP.Length, ref config);\n            if (result != VP8StatusCode.VP8_STATUS_OK)\n            {\n                throw new Exception(\"Failed WebPDecode with error \" + result);\n            }\n            LibWebp.WebPFreeDecBuffer(ref config.output);\n\n            return bmp;\n        }\n        catch (Exception ex) { throw new Exception(ex.Message + \"\\r\\nIn WebP.Decode\"); }\n        finally\n        {\n            //Unlock the pixels\n            if (bmpData != null)\n                bmp.UnlockBits(bmpData);\n\n            //Free memory\n            if (pinnedWebP.IsAllocated)\n                pinnedWebP.Free();\n        }\n    }\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/v9/Components/ImageGlass.WebP/WebPWrapper.cs#L190-L226","documentation":"Thrown in WebPWrapper.Decode after LibWebp.WebPDecode returns a status other than VP8_STATUS_OK. By this point the ABI handshake (50), header features (51), and crop bounds (52) have all passed; the failure is in the actual bitstream decode — corrupt pixel data, an unsupported VP8L/VP8X path in the bundled libwebp, truncated stream, or a malformed animated chunk. The outer catch re-wraps the message with '\\r\\nIn WebP.Decode'.","triggerScenarios":"A WebP whose header is valid but whose compressed payload is corrupt or truncated; a WebP using a feature (animation, ICC, alpha) the loaded libwebp cannot decode; memory exhaustion mid-decode surfacing as a non-OK status.","commonSituations":"Partially downloaded WebP; bit-flip corruption on disk; WebP produced by a non-standard encoder the libwebp version rejects; very large WebP combined with low memory.","solutions":["Re-acquire the file from a trusted source to rule out corruption/truncation.","Update libwebp (and the matching ImageGlass.WebP wrapper) to a version that supports the WebP variant (VP8L/VP8X/animated).","Try decoding without scaling/cropping first (use_scaling=0, use_cropping=0) to isolate whether the options or the data are at fault.","Catch the exception and mark the file undecodable; do not retry on the same bytes."],"exampleFix":"// before\nvar bmp = WebPWrapper.Decode(raw, options);\n\n// after: isolate cause by a plain decode, then handle failure\nBitmap bmp;\ntry { bmp = WebPWrapper.Decode(raw, options); }\ncatch (Exception ex) when (ex.Message.Contains(\"In WebP.Decode\"))\n{\n    Log.Warn($\"WebP decode failed for {path}: {ex.Message}\");\n    bmp = null; // or fall back to another codec\n}","handlingStrategy":"try-catch","validationCode":"// Rule out scaling/cropping as the cause: try a plain decode first.\nif (options.use_scaling == 1 || options.use_cropping == 1)\n{ var plain = new WebPDecoderOptions(); WebPWrapper.Decode(rawWebP, plain); }","typeGuard":null,"tryCatchPattern":"try { bmp = WebPWrapper.Decode(rawWebP, options); }\ncatch (Exception ex) when (ex.Message.Contains(\"WebPDecode\") && !ex.Message.Contains(\"WebPGetFeatures\"))\n{ /* bitstream decode failure — corrupt/unsupported variant */ }","preventionTips":["Re-acquire WebP from a trusted source if decode fails.","Update libwebp to support the variant (VP8L/VP8X/animated).","Do not retry the same bytes; treat as undecodable."],"tags":["webp","libwebp","decode","corrupt-data","imageglass","v9"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}