Skip to content

V3: Do not encode WEBP images exceeding max dimensions #2931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented May 30, 2025

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #2920

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new strategy to prevent encoding WEBP images whose dimensions exceed a maximum threshold. Key changes include:

  • Adding a new exception throwing method in WebpThrowHelper.
  • Introducing a dimension check in WebpEncoderCore to preemptively reject oversized images.
  • Removing redundant dimension validation in Vp8LEncoder and modifying the JPEG encoder behavior for consistency.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/ImageSharp/Formats/Webp/WebpThrowHelper.cs Added ThrowDimensionsTooLarge method to report oversized WEBP images.
src/ImageSharp/Formats/Webp/WebpEncoderCore.cs Inserted a check to call the new throw helper for oversized dimensions.
src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs Removed duplicate dimension guard previously present in WriteImageSize.
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs Updated the dimension check condition to use '>' instead of '>=' for improved consistency.
Comments suppressed due to low confidence (1)

src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs:374

  • The removal of explicit dimension checks in WriteImageSize should be validated to ensure that higher-level checks reliably prevent oversized images across all code paths.
Guard.MustBeLessThan(inputImgWidth, WebpConstants.MaxDimension, nameof(inputImgWidth));

@JimBobSquarePants JimBobSquarePants merged commit eee22e8 into release/3.1.x May 30, 2025
15 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/v3-issue-2920 branch May 30, 2025 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant