bmp: validate palette indices when decoding paletted images#30
bmp: validate palette indices when decoding paletted images#30mohammadmseet-hue wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The TIFF decoder was patched to validate palette indices in commit 3bbf4a6 ("tiff: Validate palette indices when parsing palette-color images"), but the BMP decoder has the same vulnerable pattern and was not patched. A crafted BMP file with a small palette (e.g., 2 colors) but pixel data containing out-of-range indices (e.g., 255) decodes successfully. When any consumer accesses the pixels via the returned image.Paletted, it panics with an index out of range error. This adds the same validation that the TIFF decoder received: check that each decoded pixel index is within the palette bounds before storing it.
8225727 to
d082a00
Compare
|
This PR (HEAD: d082a00) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/image/+/762680. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/762680. |
|
Message from Mohammad Seet: Patch Set 1: Done. Updated PR description to remove markdown formatting, wrap lines at ~76 characters, and fix any issues flagged by the bot. Please don’t reply on this GitHub thread. Visit golang.org/cl/762680. |
|
Message from Mohammad Seet: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/762680. |
Validate that decoded pixel indices are within palette bounds
in decodePaletted. This is the same fix applied to the TIFF
decoder in commit 3bbf4a6 (tiff: Validate palette indices
when parsing palette-color images), but for BMP.
A crafted BMP with a small palette but out-of-range pixel
indices causes a panic when the decoded image is accessed.
For example, a file with colorUsed=2 (2-color palette) but
pixel data containing index 255 causes:
runtime error: index out of range [255] with length 2
The TIFF decoder was patched to reject invalid palette
indices, but the BMP decoder has the identical vulnerable
pattern. The decoder stores the index without validation.
When any consumer calls At(x, y) on the returned
image.Paletted, it panics.
This affects all paletted BMP modes: 1, 2, 4, and 8 bits
per pixel.
The fix validates each pixel index against the palette
length during decoding and returns an error for any
out-of-range index.