Skip to content

Commit

Permalink
Fixed potential overflow in surface allocation (thanks Yves!)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 6, 2017
1 parent 312da26 commit d9e1036
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/video/SDL_surface.c
Expand Up @@ -80,7 +80,15 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,

/* Get the pixels */
if (surface->w && surface->h) {
surface->pixels = SDL_malloc(surface->h * surface->pitch);
int size = (surface->h * surface->pitch);
if (size < 0 || (size / surface->pitch) != surface->h) {
/* Overflow... */
SDL_FreeSurface(surface);
SDL_OutOfMemory();
return NULL;
}

surface->pixels = SDL_malloc(size);
if (!surface->pixels) {
SDL_FreeSurface(surface);
SDL_OutOfMemory();
Expand Down

0 comments on commit d9e1036

Please sign in to comment.