{"record":{"id":"d777566158cac05f","repo":"d2phap/ImageGlass","slug":"failed-webpgetfeatures-with-error-result","errorCode":null,"errorMessage":"Failed WebPGetFeatures with error {result}","messagePattern":"Failed WebPGetFeatures with error (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"v9/Components/ImageGlass.WebP/WebPWrapper.cs","lineNumber":151,"sourceCode":"        Bitmap? bmp = null;\n        BitmapData? bmpData = null;\n        VP8StatusCode result;\n        try\n        {\n            WebPDecoderConfig config = new WebPDecoderConfig();\n            if (LibWebp.WebPInitDecoderConfig(ref config) == 0)\n            {\n                throw new Exception(\"WebPInitDecoderConfig failed. Wrong version?\");\n            }\n            // Read the .webp input file information\n            IntPtr ptrRawWebP = pinnedWebP.AddrOfPinnedObject();\n            int height;\n            int width;\n            if (options.use_scaling == 0)\n            {\n                result = LibWebp.WebPGetFeatures(ptrRawWebP, rawWebP.Length, ref config.input);\n                if (result != VP8StatusCode.VP8_STATUS_OK)\n                    throw new Exception(\"Failed WebPGetFeatures with error \" + result);\n\n                //Test cropping values\n                if (options.use_cropping == 1)\n                {\n                    if (options.crop_left + options.crop_width > config.input.Width || options.crop_top + options.crop_height > config.input.Height)\n                        throw new Exception(\"Crop options exceeded WebP image dimensions\");\n                    width = options.crop_width;\n                    height = options.crop_height;\n                }\n            }\n            else\n            {\n                width = options.scaled_width;\n                height = options.scaled_height;\n            }\n\n            config.options.bypass_filtering = options.bypass_filtering;\n            config.options.no_fancy_upsampling = options.no_fancy_upsampling;","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/v9/Components/ImageGlass.WebP/WebPWrapper.cs#L133-L169","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar bmp = WebPWrapper.Decode(rawWebP, options);\n\n// after: signature guard + status handling\nif (rawWebP.Length < 12 ||\n    System.Text.Encoding.ASCII.GetString(rawWebP, 0, 4) != \"RIFF\" ||\n    System.Text.Encoding.ASCII.GetString(rawWebP, 8, 4) != \"WEBP\")\n    throw new InvalidDataException(\"Not a valid WebP stream.\");\nvar bmp = WebPWrapper.Decode(rawWebP, options);","handlingStrategy":"validation","validationCode":"// Reject non-WebP input before decoding.\nstatic bool IsWebP(byte[] b) => b.Length >= 12 &&\n    Encoding.ASCII.GetString(b, 0, 4) == \"RIFF\" &&\n    Encoding.ASCII.GetString(b, 8, 4) == \"WEBP\";\nif (!IsWebP(rawWebP)) throw new InvalidDataException(\"Not a WebP stream.\");","typeGuard":"static bool IsWebP(byte[] b) => b.Length >= 12 &&\n    Encoding.ASCII.GetString(b, 0, 4) == \"RIFF\" &&\n    Encoding.ASCII.GetString(b, 8, 4) == \"WEBP\";","tryCatchPattern":"try { bmp = WebPWrapper.Decode(rawWebP, options); }\ncatch (Exception ex) when (ex.Message.Contains(\"WebPGetFeatures\"))\n{ /* corrupt/truncated or non-WebP input */ }","preventionTips":["Check the RIFF/WEBP signature before decode.","Verify file integrity/length after downloads.","Update libwebp if inputs use newer WebP features."],"tags":["webp","libwebp","decode","corrupt-data","format-validation","imageglass","v9"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}