{"record":{"id":"29719874e4a1115f","repo":"babalae/better-genshin-impact","slug":"maxpixelcount-n0","errorCode":null,"errorMessage":"图片像素数量超过 {MaxPixelCount:N0} 限制。","messagePattern":"图片像素数量超过 (.+?) 限制。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Service/BannerImageService.cs","lineNumber":208,"sourceCode":"            UseDefaultCredentials = false\n        })\n        {\n            Timeout = Timeout.InfiniteTimeSpan\n        };\n        client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(\"BetterGI-Banner\", \"1.0\"));\n        return client;\n    }\n\n    private static void ValidateImage(string path)\n    {\n        try\n        {\n            var imageInfo = Image.Identify(path)\n                            ?? throw new InvalidDataException(\"下载内容不是有效的图片。\");\n            var pixelCount = checked((long)imageInfo.Width * imageInfo.Height);\n            if (pixelCount > MaxPixelCount)\n            {\n                throw new InvalidDataException($\"图片像素数量超过 {MaxPixelCount:N0} 限制。\");\n            }\n        }\n        catch (UnknownImageFormatException ex)\n        {\n            throw new InvalidDataException(\"下载内容不是支持的图片格式。\", ex);\n        }\n    }\n\n    private static void TryDeleteFile(string path)\n    {\n        try\n        {\n            if (File.Exists(path))\n            {\n                File.Delete(path);\n            }\n        }\n        catch (IOException)","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/BannerImageService.cs#L190-L226","documentation":"Thrown by ValidateImage when the downloaded image's pixel count (width * height) exceeds MaxPixelCount (40,000,000). This is a decompression-bomb guard: it rejects images that would consume excessive memory when decoded, before they can be loaded as a WPF banner.","triggerScenarios":"The downloaded image has very high resolution, e.g. 7000x6000 = 42M pixels. The checked multiplication guards against integer overflow before comparing against the cap.","commonSituations":"User selects a high-resolution photograph or a stitched panorama as the custom banner; source image is a raw scan or print-ready artwork.","solutions":["Downscale the source image so width * height is under 40,000,000 (e.g. resize to 3840x2160 = ~8.3M pixels).","Use a banner-optimized image with a typical desktop aspect ratio at a reasonable resolution.","If a higher cap is genuinely needed, raise the MaxPixelCount constant — but be aware of the memory cost when WPF decodes it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// After Image.Identify, reject early before any caller tries to decode.\nvar info = Image.Identify(path) ?? throw new InvalidDataException(\"下载内容不是有效的图片。\");\nif ((long)info.Width * info.Height > MaxPixelCount)\n{\n    throw new InvalidDataException($\"图片像素数量超过 {MaxPixelCount:N0} 限制。\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    ValidateImage(tempPath);\n}\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"像素数量\"))\n{\n    logger.LogWarning(\"Banner image exceeds pixel limit; ask user to downscale\");\n}","preventionTips":["Pre-scale banner images to a desktop-appropriate resolution (e.g. 1920x1080 or 3840x2160) before hosting.","Document the 40M-pixel cap in the UI next to the URL input so users know the limit.","If a higher cap is required, raise MaxPixelCount deliberately and audit WPF memory usage."],"tags":["image","validation","limits","banner-image","decompression-bomb"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}