Skip to content

Conversation

@NBickford-NV
Copy link
Contributor

In Issue #1861 , out-of-bounds palette indices that are greater than or equal to pal_len read from uninitialized elements of palette in stbi__expand_png_palette. This is an issue since data that was written to the stack previously could include sensitive info.

As one approach to fixing this, this merge request zero-initializes palette (and tc16 as well, since I think it might be possible for something similar to happen in stbi__compute_transparency16 if img_out_n isn't equal to img_n), so that these reads return 0 instead of uninitialized data. (We know that we can't read past the end of palette in stbi__expand_png_palette since palette has length 1024, but *palette has type stbi_uc, so the maximum element we can read is (1 << 8) * 4 + 3 == 1023.)

A different approach would be to add a check that each element of the palette is less than pal_len and exit early if so. However, my guess is the cost of a 1024-element memset is probably less on average than checking the palette index of every pixel, even if the branches in the latter fix were always predicted correctly, because it prevents vectorization inside stbi__expand_png_palette.

Thank you!

My guess is the cost of a 1024-element memset is probably less than checking the palette index of every pixel, even if the branches in the latter fix were always predicted correctly, because it prevents vectorization.

Also zero-initialize `tc16` for safety; I think it may be possible to use it uninitialized.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant