Fix a buffer overflow in `png_do_quantize`
Allocate the quantize_index array to PNG_MAX_PALETTE_LENGTH (256 bytes)
instead of num_palette bytes. This approach matches the allocation
pattern for `palette[]`, `trans_alpha[]` and `riffled_palette[]` which
were similarly oversized in libpng 1.2.1 to prevent buffer overflows
from malformed PNG files with out-of-range palette indices.
Out-of-range palette indices `index >= num_palette` will now read
identity-mapped values from the `quantize_index` array (where index N
maps to palette entry N). This prevents undefined behavior while
avoiding runtime bounds checking overhead in the performance-critical
pixel processing loop.
Reported-by: Samsung-PENTEST <Samsung-PENTEST@users.noreply.github.com>
Analyzed-by: degrigis <degrigis@users.noreply.github.com>
Bug: 463980379
Test: TreeHugger
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:31ed93cef63972fc5c656c96d7912cbac55aa4da
Merged-In: I03da129d39e82d159f8b9eb6d6d66dd36d6abf7d
Change-Id: I03da129d39e82d159f8b9eb6d6d66dd36d6abf7d
1 file changed