Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 - Limit all memory allocations to configurable values. #2705

Closed
wants to merge 4 commits into from

Conversation

JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Mar 20, 2024

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

V4 version of #2704

While the specification does not apply a limitation on BMP dimensions, on some machines attempting to decode a malformed or extremely large BMP can lead to OOM exceptions.

This change limits the dimensions to match the default set by browsers. For example Firefox

Fixes #2696

// to keep the math sane. And reject int.MinValue as a height because you can't
// get its absolute value (because -int.MinValue is one more than int.MaxValue).
const int k64KWidth = 65535;
bool sizeOk = this.infoHeader.Width > 0 && this.infoHeader.Width <= k64KWidth && this.infoHeader.Height != int.MinValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool sizeOk = this.infoHeader.Width > 0 && this.infoHeader.Width <= k64KWidth && this.infoHeader.Height != int.MinValue;
bool sizeOk = (uint)this.infoHeader.Width <= k64KWidth && this.infoHeader.Height != int.MinValue;

@JimBobSquarePants JimBobSquarePants changed the title V4 - Limit BMP image dimensions to match browser max. V4 - Limit all memory allocations to configurable values. Mar 21, 2024
@JimBobSquarePants
Copy link
Member Author

Close in favor of #2706

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.

File (detected as bmp) fails to open, consumes a lot of memory
2 participants