Skip to content

Commit

Permalink
xcf: Prevent infinite loop and/or buffer overflow on bogus data.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 7, 2018
1 parent f676999 commit 4e006ad
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions IMG_xcf.c
Expand Up @@ -483,6 +483,10 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint32 len, int bpp,
int i, size, count, j, length;
unsigned char val;

if (len == 0) { /* probably bogus data. */
return NULL;
}

t = load = (unsigned char *) SDL_malloc (len);
reallen = SDL_RWread (src, t, 1, len);

Expand Down Expand Up @@ -608,6 +612,16 @@ do_layer_surface(SDL_Surface * surface, SDL_RWops * src, xcf_header * head, xcf_
tile = load_tile(src, ox * oy * 6, hierarchy->bpp, ox, oy);
}

if (!tile) {
if (hierarchy) {
free_xcf_hierarchy(hierarchy);
}
if (level) {
free_xcf_level(level);
}
return 1;
}

p8 = tile;
p16 = (Uint16 *) p8;
p = (Uint32 *) p8;
Expand Down

0 comments on commit 4e006ad

Please sign in to comment.