Skip to content

Throw explicit InvalidImageContentException when BMP BPP is invalid.#3069

Merged
JimBobSquarePants merged 5 commits intomainfrom
js/v4-fix-3067
Mar 6, 2026
Merged

Throw explicit InvalidImageContentException when BMP BPP is invalid.#3069
JimBobSquarePants merged 5 commits intomainfrom
js/v4-fix-3067

Conversation

@JimBobSquarePants
Copy link
Member

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

This pull request strengthens validation for BMP image decoding and adds a new test to ensure invalid BMP files are handled correctly. The main change is enforcing that only valid bitsPerPixel values are accepted, preventing malformed BMP images from being processed.

Validation improvements in BMP decoding:

  • Added a check in BmpDecoderCore.Decode to ensure bitsPerPixel is one of the valid values (1, 2, 4, 8, 16, 24, or 32). If not, decoding throws an InvalidImageContentException.
  • Refactored switch statements in BmpDecoderCore.Decode to use the validated bitsPerPixel variable instead of accessing the header directly, improving code clarity and consistency. [1] [2]

Testing enhancements:

  • Added a new unit test BmpDecoder_ThrowsException_Issue3067 in BmpDecoderTests.cs to verify that decoding a BMP file with bitsPerPixel = 0 throws an InvalidImageContentException.

JimBobSquarePants and others added 4 commits March 6, 2026 14:51
…ariable'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@JimBobSquarePants JimBobSquarePants merged commit ec79a2f into main Mar 6, 2026
12 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/v4-fix-3067 branch March 6, 2026 09:19
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