using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Pbm; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Qoi; using SixLabors.ImageSharp.Formats.Tga; using SixLabors.ImageSharp.Formats.Webp; namespace ErsatzTV.Infrastructure.Images; /// /// The ImageSharp every ImageSharp decode in ErsatzTV goes through. /// /// /// It registers every format registers EXCEPT TIFF, so a TIFF is /// rejected with before any TIFF decoder code runs. /// ImageSharp 3.1.12's TIFF decoder carries GHSA-v76p-62qx-wwq2 (heap out-of-bounds write from a tiled /// fax TIFF) and GHSA-wmxv-xphr-5c9g (non-progressing BigTIFF IFD loop). TIFF is outside the artwork /// allow-list (ImageContentTypes.Accepted), so what this removes is only a remote-URL or on-disk /// TIFF graphic. It is a fresh instance rather than a Configuration.Default.Clone() because /// Clone is shallow: removing a detector from the clone would remove it from Default too. /// ImageSharpDecodingTests pins the module list against Configuration.Default, so a /// package bump that adds a format fails a test instead of silently dropping it, and /// ImageSharpSurfaceTests (ErsatzTV.Architecture.Tests) fails any production decode that does not /// take these options. /// Rationale and revisit trigger: security.imagesharp-3x-tiff-decoder-disabled. (ersatztv#929) /// public static class ImageSharpDecoding { public static Configuration Configuration { get; } = new( new PngConfigurationModule(), new JpegConfigurationModule(), new GifConfigurationModule(), new BmpConfigurationModule(), new PbmConfigurationModule(), new TgaConfigurationModule(), new WebpConfigurationModule(), new QoiConfigurationModule()); public static DecoderOptions Options() => new() { Configuration = Configuration }; public static DecoderOptions Options(uint maxFrames) => new() { Configuration = Configuration, MaxFrames = maxFrames }; }