Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,6 @@ public int EncodeAlphaImageData<TPixel>(Buffer2DRegion<TPixel> frame, IMemoryOwn
/// <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;

Expand Down
5 changes: 5 additions & 0 deletions src/ImageSharp/Formats/Webp/WebpEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ImageSharp/Formats/Webp/WebpThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Loading