1 /*
2 # Copyright 2021 Google LLC
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 ################################################################################
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include <libass/ass.h>
23
24 static ASS_Library *ass_library;
25 static ASS_Renderer *ass_renderer;
26
msg_callback(int level,const char * fmt,va_list va,void * data)27 void msg_callback(int level, const char *fmt, va_list va, void *data) {
28 }
29
30 static const int kFrameWidth = 1280;
31 static const int kFrameHeight = 720;
32
33 struct init {
initinit34 init(int frame_w, int frame_h) {
35 ass_library = ass_library_init();
36 if (!ass_library) {
37 printf("ass_library_init failed!\n");
38 exit(1);
39 }
40
41 ass_set_message_cb(ass_library, msg_callback, NULL);
42
43 ass_renderer = ass_renderer_init(ass_library);
44 if (!ass_renderer) {
45 printf("ass_renderer_init failed!\n");
46 exit(1);
47 }
48
49 ass_set_frame_size(ass_renderer, frame_w, frame_h);
50 ass_set_fonts(ass_renderer, nullptr, "sans-serif",
51 ASS_FONTPROVIDER_AUTODETECT, nullptr, 1);
52 }
53
~initinit54 ~init() {
55 ass_renderer_done(ass_renderer);
56 ass_library_done(ass_library);
57 }
58 };
59
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
61 static init initialized(kFrameWidth, kFrameHeight);
62
63 ASS_Track *track = ass_read_memory(ass_library, (char *)data, size, nullptr);
64 if (!track) return 0;
65
66 for (int i = 0; i < track->n_events; ++i) {
67 ASS_Event &ev = track->events[i];
68 long long tm = ev.Start + ev.Duration / 2;
69 ass_render_frame(ass_renderer, track, tm, nullptr);
70 }
71 ass_free_track(track);
72 return 0;
73 }
74