Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eee22e8

Browse filesBrowse files
Merge pull request #2931 from SixLabors/js/v3-issue-2920
V3: Do not encode WEBP images exceeding max dimensions
2 parents a7d6de9 + 5310d92 commit eee22e8
Copy full SHA for eee22e8

4 files changed

+9-4Lines changed: 9 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs‎

Copy file name to clipboardExpand all lines: src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
5454
Guard.NotNull(image, nameof(image));
5555
Guard.NotNull(stream, nameof(stream));
5656

57-
if (image.Width >= JpegConstants.MaxLength || image.Height >= JpegConstants.MaxLength)
57+
if (image.Width > JpegConstants.MaxLength || image.Height > JpegConstants.MaxLength)
5858
{
5959
JpegThrowHelper.ThrowDimensionsTooLarge(image.Width, image.Height);
6060
}
Collapse file

‎src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs‎

Copy file name to clipboardExpand all lines: src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,6 @@ public int EncodeAlphaImageData<TPixel>(Buffer2DRegion<TPixel> frame, IMemoryOwn
374374
/// <param name="inputImgHeight">The input image height.</param>
375375
private void WriteImageSize(int inputImgWidth, int inputImgHeight)
376376
{
377-
Guard.MustBeLessThan(inputImgWidth, WebpConstants.MaxDimension, nameof(inputImgWidth));
378-
Guard.MustBeLessThan(inputImgHeight, WebpConstants.MaxDimension, nameof(inputImgHeight));
379-
380377
uint width = (uint)inputImgWidth - 1;
381378
uint height = (uint)inputImgHeight - 1;
382379

Collapse file

‎src/ImageSharp/Formats/Webp/WebpEncoderCore.cs‎

Copy file name to clipboardExpand all lines: src/ImageSharp/Formats/Webp/WebpEncoderCore.cs
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
117117
Guard.NotNull(image, nameof(image));
118118
Guard.NotNull(stream, nameof(stream));
119119

120+
if (image.Width > WebpConstants.MaxDimension || image.Height > WebpConstants.MaxDimension)
121+
{
122+
WebpThrowHelper.ThrowDimensionsTooLarge(image.Width, image.Height);
123+
}
124+
120125
bool lossless;
121126
if (this.fileFormat is not null)
122127
{
Collapse file

‎src/ImageSharp/Formats/Webp/WebpThrowHelper.cs‎

Copy file name to clipboardExpand all lines: src/ImageSharp/Formats/Webp/WebpThrowHelper.cs
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ internal static class WebpThrowHelper
1818

1919
[DoesNotReturn]
2020
public static void ThrowInvalidImageDimensions(string errorMessage) => throw new InvalidImageContentException(errorMessage);
21+
22+
[DoesNotReturn]
23+
public static void ThrowDimensionsTooLarge(int width, int height) => throw new ImageFormatException($"Image is too large to encode at {width}x{height} for WEBP format.");
2124
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.