Skip to content

Commit 8b6b94d

Browse files
committed
xcf: deal with bogus data in rle tile decoding.
1 parent 071a199 commit 8b6b94d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

IMG_xcf.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint32 len, int bpp,
486486
t = load = (unsigned char *) SDL_malloc (len);
487487
reallen = SDL_RWread (src, t, 1, len);
488488

489-
data = (unsigned char *) SDL_malloc (x*y*bpp);
489+
data = (unsigned char *) SDL_calloc (1, x*y*bpp);
490490
for (i = 0; i < bpp; i++) {
491491
d = data + i;
492492
size = x*y;
@@ -503,6 +503,12 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint32 len, int bpp,
503503
t += 2;
504504
}
505505

506+
if (((size_t) (t - load) + length) >= len) {
507+
break; /* bogus data */
508+
} else if (length > size) {
509+
break; /* bogus data */
510+
}
511+
506512
count += length;
507513
size -= length;
508514

@@ -518,6 +524,12 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint32 len, int bpp,
518524
t += 2;
519525
}
520526

527+
if (((size_t) (t - load)) >= len) {
528+
break; /* bogus data */
529+
} else if (length > size) {
530+
break; /* bogus data */
531+
}
532+
521533
count += length;
522534
size -= length;
523535

@@ -529,6 +541,11 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint32 len, int bpp,
529541
}
530542
}
531543
}
544+
545+
if (size > 0) {
546+
break; /* just drop out, untouched data initialized to zero. */
547+
}
548+
532549
}
533550

534551
SDL_free (load);

0 commit comments

Comments
 (0)