{"record":{"id":"4196c5a64ad52b90","repo":"babalae/better-genshin-impact","slug":"locator-recognitionobject-recognition","errorCode":null,"errorMessage":"不被 Locator 支持的识别类型: {RecognitionObject.RecognitionType}","messagePattern":"不被 Locator 支持的识别类型: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Core/BgiVision/BvLocator.cs","lineNumber":89,"sourceCode":"    {\n        if (RecognitionObject.RecognitionType == RecognitionTypes.TemplateMatch)\n        {\n            var region = screen.Find(RecognitionObject);\n            if (region.IsExist())\n            {\n                return [region];\n            }\n\n            return [];\n        }\n        else if (RecognitionObject.RecognitionType == RecognitionTypes.Ocr)\n        {\n            var results = screen.FindMulti(RecognitionObject);\n            return FilterOcrResults(results, _anyTexts, RecognitionObject.Text);\n        }\n        else\n        {\n            throw new NotSupportedException($\"不被 Locator 支持的识别类型: {RecognitionObject.RecognitionType}\");\n        }\n    }\n\n    internal static List<Region> FilterOcrResults(\n        List<Region> results,\n        IReadOnlyList<string> anyTexts,\n        string text)\n    {\n        if (anyTexts.Count > 0)\n        {\n            return results.FindAll(region =>\n                anyTexts.Any(candidate => region.Text.Contains(candidate, StringComparison.Ordinal)));\n        }\n\n        return string.IsNullOrEmpty(text)\n            ? results\n            : results.FindAll(region => region.Text.Contains(text, StringComparison.Ordinal));\n    }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvLocator.cs#L71-L107","documentation":"Thrown by ValidatePixelCount when the decoded image has non-positive dimensions or when width * height exceeds MaxPixelCount (40,000,000 pixels). This is a safety guard against decompression-bomb attacks and excessive memory usage from large images. The check uses a long cast to avoid integer overflow in the multiplication.","triggerScenarios":"ValidatePixelCount(width, height) is called after decoding; triggers when width <= 0, height <= 0, or (long)width * height > 40_000_000. Happens with very high-resolution images (e.g. 8000x6000 = 48M pixels) or corrupted metadata reporting absurd dimensions.","commonSituations":"Markdown references a very large wallpaper or screenshot, a malformed image header reports fake huge dimensions, or a legitimate large diagram exceeds the conservative 40M-pixel limit.","solutions":["Resize the image to under 40 million total pixels (e.g. max ~6300x6300) before referencing it.","If the dimensions are bogus (corrupt header), re-export the image from its source.","Increase MaxPixelCount if large images are a legitimate requirement (recompile)."],"exampleFix":"// before\nif (width <= 0 || height <= 0 || (long)width * height > MaxPixelCount)\n    throw new InvalidDataException(\"图片像素尺寸无效或超过安全限制。\");\n\n// after — downscale large images instead of rejecting\nif (width <= 0 || height <= 0)\n    throw new InvalidDataException(\"图片尺寸无效。\");\nif ((long)width * height > MaxPixelCount)\n{\n    var scale = Math.Sqrt((double)MaxPixelCount / (width * height));\n    // apply downscale via TransformedBitmap before returning\n}","handlingStrategy":"validation","validationCode":"// Pre-check dimensions after decode, before creating BitmapSource\nValidatePixelCount(image.Width, image.Height);\n// Or downscale if over limit","typeGuard":"static bool IsPixelCountSafe(int w, int h) =>\n    w > 0 && h > 0 && (long)w * h <= MaxPixelCount;","tryCatchPattern":"try { ValidatePixelCount(width, height); }\ncatch (InvalidDataException) { /* downscale or return placeholder */ }","preventionTips":["Resize images to under 40M pixels before embedding in Markdown.","Implement automatic downscaling for oversized images.","Use the long-cast multiplication to avoid integer overflow in dimension checks."],"tags":["markdown","image","pixel-limit","decompression-bomb","security"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}