d2phap/ImageGlass · error · Exception
Failed WebPGetFeatures with error {result}
Error message
Failed WebPGetFeatures with error {result} What it means
Thrown in WebPWrapper.Decode when LibWebp.WebPGetFeatures returns a status other than VP8_STATUS_OK. WebPGetFeatures parses the WebP bitstream header (dimensions, alpha, animation flags); a non-OK status means the input bytes are not a valid WebP, are truncated, or are a WebP container the decoder cannot read. This happens AFTER the ABI handshake (error 50) has passed, so the native library is fine — the data is the problem.
Source
Thrown at v9/Components/ImageGlass.WebP/WebPWrapper.cs:151
Bitmap? bmp = null;
BitmapData? bmpData = null;
VP8StatusCode result;
try
{
WebPDecoderConfig config = new WebPDecoderConfig();
if (LibWebp.WebPInitDecoderConfig(ref config) == 0)
{
throw new Exception("WebPInitDecoderConfig failed. Wrong version?");
}
// Read the .webp input file information
IntPtr ptrRawWebP = pinnedWebP.AddrOfPinnedObject();
int height;
int width;
if (options.use_scaling == 0)
{
result = LibWebp.WebPGetFeatures(ptrRawWebP, rawWebP.Length, ref config.input);
if (result != VP8StatusCode.VP8_STATUS_OK)
throw new Exception("Failed WebPGetFeatures with error " + result);
//Test cropping values
if (options.use_cropping == 1)
{
if (options.crop_left + options.crop_width > config.input.Width || options.crop_top + options.crop_height > config.input.Height)
throw new Exception("Crop options exceeded WebP image dimensions");
width = options.crop_width;
height = options.crop_height;
}
}
else
{
width = options.scaled_width;
height = options.scaled_height;
}
config.options.bypass_filtering = options.bypass_filtering;
config.options.no_fancy_upsampling = options.no_fancy_upsampling;View on GitHub (pinned to 4a3c4fecef)
Solutions
- Validate the input starts with the WebP RIFF signature ('RIFF'....'WEBP') before calling Decode; reject early with a clear error.
- Re-fetch or re-encode the source WebP from a known-good origin to rule out truncation/corruption.
- Update libwebp to a version that supports the WebP feature set in your inputs.
- Catch the exception at the call site and treat the file as undecodable rather than crashing the batch.
Example fix
// before
var bmp = WebPWrapper.Decode(rawWebP, options);
// after: signature guard + status handling
if (rawWebP.Length < 12 ||
System.Text.Encoding.ASCII.GetString(rawWebP, 0, 4) != "RIFF" ||
System.Text.Encoding.ASCII.GetString(rawWebP, 8, 4) != "WEBP")
throw new InvalidDataException("Not a valid WebP stream.");
var bmp = WebPWrapper.Decode(rawWebP, options); Defensive patterns
Strategy: validation
Validate before calling
// Reject non-WebP input before decoding.
static bool IsWebP(byte[] b) => b.Length >= 12 &&
Encoding.ASCII.GetString(b, 0, 4) == "RIFF" &&
Encoding.ASCII.GetString(b, 8, 4) == "WEBP";
if (!IsWebP(rawWebP)) throw new InvalidDataException("Not a WebP stream."); Type guard
static bool IsWebP(byte[] b) => b.Length >= 12 &&
Encoding.ASCII.GetString(b, 0, 4) == "RIFF" &&
Encoding.ASCII.GetString(b, 8, 4) == "WEBP"; Try / catch
try { bmp = WebPWrapper.Decode(rawWebP, options); }
catch (Exception ex) when (ex.Message.Contains("WebPGetFeatures"))
{ /* corrupt/truncated or non-WebP input */ } Prevention
- Check the RIFF/WEBP signature before decode.
- Verify file integrity/length after downloads.
- Update libwebp if inputs use newer WebP features.
When it happens
Trigger: Passing non-WebP bytes (wrong format, a JPEG/PNG mislabeled .webp); a truncated/corrupt WebP downloaded incompletely; a WebP with features this libwebp build doesn't support (e.g. extended container without the right build); a zero-length or near-empty buffer.
Common situations: Reading a .webp from an unreliable network/clipboard that got truncated; a file with a renamed extension; feeding a WebP that uses a newer feature than the bundled libwebp supports.
Related errors
- Failed WebPDecode 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/d777566158cac05f.
Report an issue: GitHub.