babalae/better-genshin-impact · error · InvalidDataException

图片像素尺寸无效或超过安全限制。

Error message

图片像素尺寸无效或超过安全限制。

What it means

Error "图片像素尺寸无效或超过安全限制。" thrown in babalae/better-genshin-impact.

Source

Thrown at BetterGenshinImpact/View/Controls/Markdown/MarkdownImageLoader.cs:229

                    WpfPixelFormats.Bgra32,
                    null,
                    pixels,
                    image.Width * 4);
                bitmapSource.Freeze();
                return new MarkdownImageResult(bitmapSource, image.Width, image.Height);
            }
            catch (Exception imageSharpException)
            {
                throw new InvalidDataException("无法解码 Markdown 图片。", imageSharpException);
            }
        }
    }

    private static void ValidatePixelCount(int width, int height)
    {
        if (width <= 0 || height <= 0 || (long)width * height > MaxPixelCount)
        {
            throw new InvalidDataException("图片像素尺寸无效或超过安全限制。");
        }
    }

    private static string GetCacheKey(Uri source)
    {
        if (!source.IsFile)
        {
            return source.AbsoluteUri;
        }

        var fileInfo = new FileInfo(source.LocalPath);
        return fileInfo.Exists
            ? $"{fileInfo.FullName}|{fileInfo.LastWriteTimeUtc.Ticks}|{fileInfo.Length}"
            : fileInfo.FullName;
    }
}

internal sealed class MarkdownImagePresenter : Grid

View on GitHub (pinned to a7cb36712d)

Solutions

  1. 压缩图片尺寸使其低于安全限制
  2. 检查图片像素尺寸是否有效(大于0)
  3. 使用正常尺寸的图片替换

Example fix

缩小图片像素尺寸(如限制在合理分辨率内)后再引用。

When it happens

Trigger: ValidatePixelCount 检查图片宽或高<=0,或宽×高超过 MaxPixelCount 安全上限时抛出。

Common situations: 引用了像素尺寸异常巨大(像素炸弹)的图片。


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/d3ecd593dfa1b9e6. Report an issue: GitHub.