Skip to content

Commit 7acc018

Browse files
committed
Fix integer overflow in the TGA loader (found with afl-fuzz).
git-svn-id: svn://svn.icculus.org/twilight/trunk/dpvideo@12255 d7cf8633-e32d-0410-b094-e92efae38249
1 parent 3cab434 commit 7acc018

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tgafile.c

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
#include <limits.h>
23
#include <stdlib.h>
34
#include <stdio.h>
45
#include <string.h>
@@ -65,6 +66,12 @@ tgafile_t *loadtga(char *filename)
6566
columns = targa.width;
6667
rows = targa.height;
6768

69+
if (columns <= 0 || rows <= 0 || rows > (INT_MAX / 3) / columns) {
70+
printf ("LoadTGA: %i by %i is an invalid image size\n", columns, rows);
71+
free(data);
72+
return NULL;
73+
}
74+
6875
pixels = malloc(columns * rows * 3);
6976
if (!pixels)
7077
{

0 commit comments

Comments
 (0)