Skip to content

Backport: V3 - Throw explicit InvalidImageContentException when BMP BPP is invalid.#3068

Open
JimBobSquarePants wants to merge 4 commits intorelease/3.1.xfrom
js/fix-3067
Open

Backport: V3 - Throw explicit InvalidImageContentException when BMP BPP is invalid.#3068
JimBobSquarePants wants to merge 4 commits intorelease/3.1.xfrom
js/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 improves the robustness of the BMP decoder by adding stricter validation for the bitsPerPixel field and introducing a corresponding unit test. The main change ensures that invalid or unsupported bitsPerPixel values are properly detected and handled, preventing potential errors when decoding malformed BMP files.

Validation improvements in BMP decoding:

  • Refactored the Decode method in BmpDecoderCore.cs to use a local bitsPerPixel variable for clarity and consistency throughout the code.
  • Added a validation check in Decode to throw an InvalidImageContentException when bitsPerPixel is not in the supported range (>0 and <=8, 16, 24, 32), preventing decoding of invalid BMP files.

Testing enhancements:

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

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