Skip to content

Commit

Permalink
Always create a full 256-entry map in case color values are out of range
Browse files Browse the repository at this point in the history
Fixes #5042
  • Loading branch information
slouken committed Nov 30, 2021
1 parent 056c099 commit 8c91cf7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/video/SDL_pixels.c
Expand Up @@ -947,7 +947,7 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical)
}
*identical = 0;
}
map = (Uint8 *) SDL_malloc(src->ncolors);
map = (Uint8 *) SDL_calloc(256, sizeof(Uint8));
if (map == NULL) {
SDL_OutOfMemory();
return (NULL);
Expand All @@ -971,7 +971,7 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
SDL_Palette *pal = src->palette;

bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
map = (Uint8 *) SDL_calloc(256, bpp);
if (map == NULL) {
SDL_OutOfMemory();
return (NULL);
Expand Down

1 comment on commit 8c91cf7

@carnil
Copy link

@carnil carnil commented on 8c91cf7 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks this fix is related to CVE-2021-33657

Please sign in to comment.