2019-01-08 19:17:29 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
2019-02-16 18:36:03 +00:00
|
|
|
#include <string.h>
|
2019-01-08 19:17:29 +00:00
|
|
|
#include "gif_lib.h"
|
|
|
|
|
2019-02-15 22:07:49 +00:00
|
|
|
struct gifUserData {
|
|
|
|
size_t gifLen;
|
2019-02-16 18:36:03 +00:00
|
|
|
uint8_t *gifData;
|
2019-02-15 22:07:49 +00:00
|
|
|
};
|
2019-01-08 19:17:29 +00:00
|
|
|
|
2019-02-15 22:07:49 +00:00
|
|
|
int stub_input_reader (GifFileType *gifFileType, GifByteType *gifByteType, int len) {
|
|
|
|
struct gifUserData *gud = gifFileType->UserData;
|
2019-02-16 18:36:03 +00:00
|
|
|
if (gud->gifLen == 0)
|
|
|
|
return 0;
|
2019-02-15 22:07:49 +00:00
|
|
|
int read_len = (len > gud->gifLen ? gud->gifLen : len);
|
|
|
|
memcpy(gifByteType, gud->gifData, read_len);
|
2019-02-16 18:36:03 +00:00
|
|
|
gud->gifData += read_len;
|
|
|
|
gud->gifLen -= read_len;
|
2019-02-15 22:07:49 +00:00
|
|
|
return read_len;
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:17:29 +00:00
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
|
|
|
{
|
|
|
|
GifFileType *GifFile;
|
2019-02-15 22:07:49 +00:00
|
|
|
int Error;
|
2019-02-16 18:36:03 +00:00
|
|
|
uint8_t *gifData = (uint8_t *)malloc(Size);
|
|
|
|
memcpy(gifData, Data, Size);
|
2019-02-15 22:07:49 +00:00
|
|
|
struct gifUserData gUData = {Size, gifData};
|
|
|
|
|
|
|
|
GifFile = DGifOpen((void *)&gUData, stub_input_reader, &Error);
|
2019-02-16 18:36:03 +00:00
|
|
|
if (GifFile != NULL) {
|
|
|
|
DGifSlurp(GifFile);
|
|
|
|
DGifCloseFile(GifFile, &Error);
|
2019-02-15 22:07:49 +00:00
|
|
|
}
|
|
|
|
free(gifData);
|
2019-01-08 19:17:29 +00:00
|
|
|
return 0;
|
2019-02-15 22:07:49 +00:00
|
|
|
}
|