Fixes issue #1861 by zero-initializing palette.
#1863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Issue #1861 , out-of-bounds palette indices that are greater than or equal to
pal_lenread from uninitialized elements ofpaletteinstbi__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(andtc16as well, since I think it might be possible for something similar to happen instbi__compute_transparency16ifimg_out_nisn't equal toimg_n), so that these reads return 0 instead of uninitialized data. (We know that we can't read past the end ofpaletteinstbi__expand_png_palettesincepalettehas length 1024, but*palettehas typestbi_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_lenand 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 insidestbi__expand_png_palette.Thank you!