--- /dev/null
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+
+#include <thumbnail_util.h>
+
+#define array_len(arr) (sizeof(arr)/sizeof(arr[0]))
+
+#define file_num ( input_data->file_n % (array_len(file_name_arr)) )
+#define file_name file_name_arr[file_num]
+
+struct input {
+ unsigned int file_n;
+
+ const uint8_t data[0];
+};
+
+static inline struct input *input_data_init(const uint8_t *data, size_t *size)
+{
+ struct input *res = NULL;
+ if (*size < sizeof(struct input))
+ return res;
+ *size = *size - sizeof(*res);
+ res = (struct input*)data;
+ return res;
+}
+
+
+const char *file_name_arr[] = {
+ "/tmp/%d.3gp",
+ "/tmp/%d.asf",
+ "/tmp/%d.avi",
+ "/tmp/%d.mkv",
+ "/tmp/%d.mp4",
+ "/tmp/%d.ogg",
+ "/tmp/%d.mmf",
+ "/tmp/%d.mpeg",
+ "",
+};
+
+void make_file(const char *file, const uint8_t *data, size_t size)
+{
+ FILE *f;
+ char file_line[256];
+ sprintf(file_line, file, getpid());
+ f = fopen(file_line, "w+");
+ if (f == NULL)
+ return;
+ fwrite(data, size, 1, f);
+ fclose(f);
+}
+
+void rm_file(const char *file)
+{
+ char file_line[256];
+ sprintf(file_line, file, getpid());
+ remove(file_line);
+}
+
+
+static thumbnail_h g_thumb_h;
+static int thumbnail_completed = 0;
+
+static void thumbnail_completed_cb(thumbnail_util_error_e error, const char *request_id,
+ int raw_width, int raw_height, unsigned char *raw_data,
+ int raw_size, void *user_data)
+{
+ thumbnail_completed = 1;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ struct input *input_data = NULL;
+ char *request_id = NULL;
+ int error_code;
+
+ input_data = input_data_init(data, &size);
+ if (input_data == NULL)
+ goto Exception;
+
+ make_file(file_name, input_data->data, size);
+
+ // Start test
+ thumbnail_completed = 0;
+
+ // Create thumbnail instance.
+ error_code = thumbnail_util_create(&g_thumb_h);
+ if (THUMBNAIL_UTIL_ERROR_NONE != error_code)
+ goto file_rm;
+
+ error_code = thumbnail_util_set_path(g_thumb_h, file_name);
+ if (THUMBNAIL_UTIL_ERROR_NONE != error_code)
+ goto th_destroy;
+
+ // Extract the thumbnail from the given file.
+
+ error_code = thumbnail_util_extract(g_thumb_h, thumbnail_completed_cb, NULL, &request_id);
+ if (THUMBNAIL_UTIL_ERROR_NONE != error_code)
+ goto th_destroy;
+
+ while(!thumbnail_completed);
+
+th_destroy:
+ free(request_id);
+ error_code = thumbnail_util_destroy(g_thumb_h);
+file_rm:
+ rm_file(file_name);
+Exception:
+ return 0;
+}