mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
Fixed crash in bug 3367 - RGBA_FROM_PIXEL macro can't handle SDL_PIXELFORMAT_ARGB2101010
Simon Hug The RGBA_FROM_PIXEL macro in src/video/blit.h [1] is not designed to work with more than 8 bits per channel and the ARGB2101010 format makes it read outside of the array bounds causing access violations. This can happen during blitting with the BlitNtoNPixelAlpha and SDL_Blit_Slow functions. When SDL_InitFormat tries to calculate the loss of the channels [2], the Uint8 will wrap around and it will end up at 254 for the 10-bit channels. Clearly way over the 9 entries of the SDL_expand_byte array. (Not that a signed integer would help.) Then the macro tries to access the lookup table with the channel value which could be up to 1023. If the previous indirection didn't cause an access violation this one will. I guess it's not worth modifying this macro for a format that only a few will use. It will only make the other blitters slower. I don't have good ideas to solve this issue. Attached is a test case that does three blits. A copy one that work and the two that use the functions mentioned above. [1] https://hg.libsdl.org/SDL/file/cd1994d4f3c6/src/video/SDL_blit.h#l303 [2] https://hg.libsdl.org/SDL/file/cd1994d4f3c6/src/video/SDL_pixels.c#l540
This commit is contained in:
parent
df5898b0d3
commit
1da252c2d8
@ -245,6 +245,10 @@ SDL_CalculateBlit(SDL_Surface * surface)
|
||||
/* Choose a standard blit function */
|
||||
if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
|
||||
blit = SDL_BlitCopy;
|
||||
} else if (surface->format->Rloss > 8 || dst->format->Rloss > 8) {
|
||||
/* Greater than 8 bits per channel not supported yet */
|
||||
SDL_InvalidateMap(map);
|
||||
return SDL_SetError("Blit combination not supported");
|
||||
} else if (surface->format->BitsPerPixel < 8 &&
|
||||
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
|
||||
blit = SDL_CalculateBlit0(surface);
|
||||
|
Loading…
Reference in New Issue
Block a user