Skip to content

Commit 4e006ad

Browse files
committed
xcf: Prevent infinite loop and/or buffer overflow on bogus data.
1 parent f676999 commit 4e006ad

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

IMG_xcf.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint32 len, int bpp,
483483
int i, size, count, j, length;
484484
unsigned char val;
485485

486+
if (len == 0) { /* probably bogus data. */
487+
return NULL;
488+
}
489+
486490
t = load = (unsigned char *) SDL_malloc (len);
487491
reallen = SDL_RWread (src, t, 1, len);
488492

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

615+
if (!tile) {
616+
if (hierarchy) {
617+
free_xcf_hierarchy(hierarchy);
618+
}
619+
if (level) {
620+
free_xcf_level(level);
621+
}
622+
return 1;
623+
}
624+
611625
p8 = tile;
612626
p16 = (Uint16 *) p8;
613627
p = (Uint32 *) p8;

0 commit comments

Comments
 (0)