summaryrefslogtreecommitdiff
path: root/tests/gif/uninitialized_memory_read.c
blob: 566fc4acc91c5f90e5dadc4e1b17418d2e148ccd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Test for uninitialized color map entries
 *
 * We're reading a crafted GIF which consists of 16x16 color blocks and which
 * has only two palette entries in the global color map, but uses other palette
 * indexes as well. We verify whether all undefined palette indexes produce the
 * color black.
 *
 * See also <CAKm_7a-AO++B6cXYWM_DtycPENG5WNWK7NSEvQ5OmZziMY_JyA@mail.gmail.com>
 * which had been sent to security@libgd.org.
 */


#include "gd.h"
#include "gdtest.h"


int main()
{
    gdImagePtr im;
    FILE *fp;
    int i, j, col;

    fp = gdTestFileOpen2("gif", "unitialized_memory_read.gif");
    gdTestAssert(fp != NULL);
    im = gdImageCreateFromGif(fp);
    gdTestAssert(im != NULL);
    fclose(fp);

    for (i = 0; i < gdImageSX(im); i += 16) {
        for (j = 0; j < gdImageSY(im); j += 16) {
            if (gdImageGetPixel(im, i, j) >= 2) {
                col = gdImageGetTrueColorPixel(im, i, j);
                gdTestAssertMsg(col == 0, "(%d,%d): expected color 0, but got %d\n", i, j, col);
            }
        }
    }

    gdImageDestroy(im);

    return gdNumFailures();
}