diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index fe831caf83..24d187830f 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp Guard.NotNull(stream, nameof(stream)); var decoder = new BmpDecoderCore(configuration, this); - return decoder.Decode(configuration, stream, CreateLargeImageException); + return decoder.Decode(configuration, stream); } /// @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp Guard.NotNull(stream, nameof(stream)); var decoder = new BmpDecoderCore(configuration, this); - return decoder.DecodeAsync(configuration, stream, CreateLargeImageException, cancellationToken); + return decoder.DecodeAsync(configuration, stream, cancellationToken); } /// @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { Guard.NotNull(stream, nameof(stream)); - return new BmpDecoderCore(configuration, this).Identify(configuration, stream, CreateLargeImageException); + return new BmpDecoderCore(configuration, this).Identify(configuration, stream); } /// @@ -72,12 +72,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { Guard.NotNull(stream, nameof(stream)); - return new BmpDecoderCore(configuration, this).IdentifyAsync(configuration, stream, CreateLargeImageException, cancellationToken); - } - - private static InvalidImageContentException CreateLargeImageException(InvalidMemoryOperationException ex, Size dims) - { - return new InvalidImageContentException($"Cannot decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex); + return new BmpDecoderCore(configuration, this).IdentifyAsync(configuration, stream, cancellationToken); } } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index e42f9c9f25..f665cc0ab5 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -63,14 +63,12 @@ namespace SixLabors.ImageSharp.Formats.Gif } /// - public async Task IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) + public Task IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) { Guard.NotNull(stream, nameof(stream)); var decoder = new GifDecoderCore(configuration, this); - - using var bufferedStream = new BufferedReadStream(configuration, stream); - return await decoder.IdentifyAsync(configuration, bufferedStream, cancellationToken); + return decoder.IdentifyAsync(configuration, stream, cancellationToken); } } } diff --git a/src/ImageSharp/Formats/ImageDecoderUtilities.cs b/src/ImageSharp/Formats/ImageDecoderUtilities.cs index 5e4aeb9eb6..a5f5819bdd 100644 --- a/src/ImageSharp/Formats/ImageDecoderUtilities.cs +++ b/src/ImageSharp/Formats/ImageDecoderUtilities.cs @@ -127,14 +127,10 @@ namespace SixLabors.ImageSharp.Formats } } - public static IImageInfo Identify(this IImageDecoderInternals decoder, Configuration configuration, Stream stream) - => decoder.Identify(configuration, stream, DefaultLargeImageExceptionFactory); - public static IImageInfo Identify( this IImageDecoderInternals decoder, Configuration configuration, - Stream stream, - Func largeImageExceptionFactory) + Stream stream) { using BufferedReadStream bufferedReadStream = new BufferedReadStream(configuration, stream); @@ -144,7 +140,7 @@ namespace SixLabors.ImageSharp.Formats } catch (InvalidMemoryOperationException ex) { - throw largeImageExceptionFactory(ex, decoder.Dimensions); + throw new InvalidImageContentException(decoder.Dimensions, ex); } } diff --git a/src/ImageSharp/Formats/ImageExtesions.Save.cs b/src/ImageSharp/Formats/ImageExtensions.Save.cs similarity index 100% rename from src/ImageSharp/Formats/ImageExtesions.Save.cs rename to src/ImageSharp/Formats/ImageExtensions.Save.cs diff --git a/src/ImageSharp/Formats/ImageExtesions.Save.tt b/src/ImageSharp/Formats/ImageExtensions.Save.tt similarity index 100% rename from src/ImageSharp/Formats/ImageExtesions.Save.tt rename to src/ImageSharp/Formats/ImageExtensions.Save.tt diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 8b2bbd701d..c3d9618c8c 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -17,7 +17,6 @@ SixLabors.ImageSharp Image Resize Crop Gif Jpg Jpeg Bitmap Png Core SixLabors.ImageSharp - SA1636 @@ -133,10 +132,10 @@ True PorterDuffFunctions.Generated.tt - + True True - ImageExtesions.Save.tt + ImageExtensions.Save.tt @@ -213,9 +212,9 @@ DefaultPixelBlenders.Generated.cs TextTemplatingFileGenerator - + TextTemplatingFileGenerator - ImageExtesions.Save.cs + ImageExtensions.Save.cs