1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <libass/ass.h>
5
6 static ASS_Library *ass_library;
7 static ASS_Renderer *ass_renderer;
8
msg_callback(int level,const char * fmt,va_list va,void * data)9 void msg_callback(int level, const char *fmt, va_list va, void *data) {
10 }
11
12 static const int kFrameWidth = 1280;
13 static const int kFrameHeight = 720;
14
init(int frame_w,int frame_h)15 static bool init(int frame_w, int frame_h) {
16 ass_library = ass_library_init();
17 if (!ass_library) {
18 printf("ass_library_init failed!\n");
19 exit(1);
20 }
21
22 ass_set_message_cb(ass_library, msg_callback, NULL);
23
24 ass_renderer = ass_renderer_init(ass_library);
25 if (!ass_renderer) {
26 printf("ass_renderer_init failed!\n");
27 exit(1);
28 }
29
30 ass_set_frame_size(ass_renderer, frame_w, frame_h);
31 ass_set_fonts(ass_renderer, nullptr, "sans-serif",
32 ASS_FONTPROVIDER_AUTODETECT, nullptr, 1);
33 return true;
34 }
35
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)36 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
37 static bool initialized = init(kFrameWidth, kFrameHeight);
38
39 ASS_Track *track = ass_read_memory(ass_library, (char *)data, size, nullptr);
40 if (!track) return 0;
41
42 for (int i = 0; i < track->n_events; ++i) {
43 ASS_Event &ev = track->events[i];
44 long long tm = ev.Start + ev.Duration / 2;
45 ass_render_frame(ass_renderer, track, tm, nullptr);
46 }
47 ass_free_track(track);
48 return 0;
49 }
50