d2phap/ImageGlass · error · Exception
Failed WebPDecode with error {result}
Error message
Failed WebPDecode with error {result} What it means
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'.
Source
Thrown at v9/Components/ImageGlass.WebP/WebPWrapper.cs:208
{
config.output.colorspace = WEBP_CSP_MODE.MODE_BGR;
bmp = new Bitmap(config.input.Width, config.input.Height, PixelFormat.Format24bppRgb);
}
bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
// Specify the output format
config.output.u.RGBA.rgba = bmpData.Scan0;
config.output.u.RGBA.stride = bmpData.Stride;
config.output.u.RGBA.size = (UIntPtr)(bmp.Height * bmpData.Stride);
config.output.height = bmp.Height;
config.output.width = bmp.Width;
config.output.is_external_memory = 1;
// Decode
result = LibWebp.WebPDecode(ptrRawWebP, rawWebP.Length, ref config);
if (result != VP8StatusCode.VP8_STATUS_OK)
{
throw new Exception("Failed WebPDecode with error " + result);
}
LibWebp.WebPFreeDecBuffer(ref config.output);
return bmp;
}
catch (Exception ex) { throw new Exception(ex.Message + "\r\nIn WebP.Decode"); }
finally
{
//Unlock the pixels
if (bmpData != null)
bmp.UnlockBits(bmpData);
//Free memory
if (pinnedWebP.IsAllocated)
pinnedWebP.Free();
}
}
View on GitHub (pinned to 4a3c4fecef)
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.
Example fix
// before
var bmp = WebPWrapper.Decode(raw, options);
// after: isolate cause by a plain decode, then handle failure
Bitmap bmp;
try { bmp = WebPWrapper.Decode(raw, options); }
catch (Exception ex) when (ex.Message.Contains("In WebP.Decode"))
{
Log.Warn($"WebP decode failed for {path}: {ex.Message}");
bmp = null; // or fall back to another codec
} Defensive patterns
Strategy: try-catch
Validate before calling
// Rule out scaling/cropping as the cause: try a plain decode first.
if (options.use_scaling == 1 || options.use_cropping == 1)
{ var plain = new WebPDecoderOptions(); WebPWrapper.Decode(rawWebP, plain); } Try / catch
try { bmp = WebPWrapper.Decode(rawWebP, options); }
catch (Exception ex) when (ex.Message.Contains("WebPDecode") && !ex.Message.Contains("WebPGetFeatures"))
{ /* bitstream decode failure — corrupt/unsupported variant */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed WebPGetFeatures with error {result}
- Crop options exceeded WebP image dimensions
- WebPInitDecoderConfig failed. Wrong version?
- Bitmap contains no data.
- The base64 content is invalid.
AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13).
Data as JSON: /api/errors/ccf7f1b463376f3f.
Report an issue: GitHub.