Browse Source
Merge pull request #2930 from SixLabors/js/issue-2920
Do not encode WEBP images exceeding max dimensions
pull/2936/head
James Jackson-South
8 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
9 additions and
4 deletions
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
src/ImageSharp/Formats/Webp/WebpEncoderCore.cs
src/ImageSharp/Formats/Webp/WebpThrowHelper.cs
@ -58,7 +58,7 @@ internal sealed unsafe partial class JpegEncoderCore
Guard . NotNull ( image , nameof ( image ) ) ;
Guard . NotNull ( stream , nameof ( stream ) ) ;
if ( image . Width > = JpegConstants . MaxLength | | image . Height > = JpegConstants . MaxLength )
if ( image . Width > JpegConstants . MaxLength | | image . Height > JpegConstants . MaxLength )
{
JpegThrowHelper . ThrowDimensionsTooLarge ( image . Width , image . Height ) ;
}
@ -371,9 +371,6 @@ internal class Vp8LEncoder : IDisposable
/// <param name="inputImgHeight">The input image height.</param>
private void WriteImageSize ( int inputImgWidth , int inputImgHeight )
{
Guard . MustBeLessThan ( inputImgWidth , WebpConstants . MaxDimension , nameof ( inputImgWidth ) ) ;
Guard . MustBeLessThan ( inputImgHeight , WebpConstants . MaxDimension , nameof ( inputImgHeight ) ) ;
uint width = ( uint ) inputImgWidth - 1 ;
uint height = ( uint ) inputImgHeight - 1 ;
@ -132,6 +132,11 @@ internal sealed class WebpEncoderCore
Guard . NotNull ( image , nameof ( image ) ) ;
Guard . NotNull ( stream , nameof ( stream ) ) ;
if ( image . Width > WebpConstants . MaxDimension | | image . Height > WebpConstants . MaxDimension )
{
WebpThrowHelper . ThrowDimensionsTooLarge ( image . Width , image . Height ) ;
}
bool lossless ;
if ( this . fileFormat is not null )
{
@ -18,4 +18,7 @@ internal static class WebpThrowHelper
[DoesNotReturn]
public static void ThrowInvalidImageDimensions ( string errorMessage ) = > throw new InvalidImageContentException ( errorMessage ) ;
[DoesNotReturn]
public static void ThrowDimensionsTooLarge ( int width , int height ) = > throw new ImageFormatException ( $"Image is too large to encode at {width}x{height} for WEBP format." ) ;
}