/src/hoextdown/test/hoedown_fuzzer.c
Line | Count | Source |
1 | | #include <stddef.h> |
2 | | #include <stdint.h> |
3 | | #include <errno.h> |
4 | | #include <stdio.h> |
5 | | #include <stdlib.h> |
6 | | #include <string.h> |
7 | | |
8 | | #include "document.h" |
9 | | #include "html.h" |
10 | | #include "context_test.h" |
11 | | |
12 | | enum renderer_type { |
13 | | RENDERER_HTML, |
14 | | RENDERER_HTML_TOC, |
15 | | RENDERER_CONTEXT_TEST |
16 | | }; |
17 | | |
18 | 10.7k | #define DEF_IUNIT 1024 |
19 | 10.7k | #define DEF_OUNIT 64 |
20 | 10.7k | #define DEF_MAX_NESTING 16 |
21 | | |
22 | | struct option_data { |
23 | | char *basename; |
24 | | int done; |
25 | | |
26 | | /* time reporting */ |
27 | | int show_time; |
28 | | |
29 | | /* I/O */ |
30 | | size_t iunit; |
31 | | size_t ounit; |
32 | | const char *filename; |
33 | | |
34 | | /* renderer */ |
35 | | enum renderer_type renderer; |
36 | | int toc_level; |
37 | | hoedown_html_flags html_flags; |
38 | | |
39 | | /* document */ |
40 | | uint8_t attr_activation; |
41 | | |
42 | | /* parsing */ |
43 | | hoedown_extensions extensions; |
44 | | size_t max_nesting; |
45 | | |
46 | | /* link_attributes */ |
47 | | int link_attributes; |
48 | | }; |
49 | | |
50 | 10.7k | int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
51 | 10.7k | struct option_data opt; |
52 | 10.7k | hoedown_buffer *ib, *ob, *meta; |
53 | 10.7k | hoedown_renderer *renderer = NULL; |
54 | 10.7k | void (*renderer_free)(hoedown_renderer *) = NULL; |
55 | 10.7k | hoedown_document *document; |
56 | | |
57 | | /* Parse options */ |
58 | 10.7k | opt.basename = "fuzz"; |
59 | 10.7k | opt.done = 0; |
60 | 10.7k | opt.show_time = 0; |
61 | 10.7k | opt.iunit = DEF_IUNIT; |
62 | 10.7k | opt.ounit = DEF_OUNIT; |
63 | 10.7k | opt.filename = NULL; |
64 | 10.7k | opt.renderer = RENDERER_HTML; |
65 | 10.7k | opt.toc_level = 0; |
66 | 10.7k | opt.attr_activation = 0; |
67 | | // opt.html_flags = 0; |
68 | 10.7k | opt.html_flags = HOEDOWN_HTML_SKIP_HTML | HOEDOWN_HTML_ESCAPE | HOEDOWN_HTML_HARD_WRAP | HOEDOWN_HTML_USE_XHTML | HOEDOWN_HTML_USE_TASK_LIST | HOEDOWN_HTML_LINE_CONTINUE | HOEDOWN_HTML_HEADER_ID | HOEDOWN_HTML_FENCED_CODE_SCRIPT; |
69 | | //opt.extensions = 0; |
70 | 10.7k | opt.extensions = HOEDOWN_EXT_TABLES | HOEDOWN_EXT_MULTILINE_TABLES | HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_FOOTNOTES | HOEDOWN_EXT_DEFINITION_LISTS | HOEDOWN_EXT_BLOCKQUOTE_EMPTY_LINE | HOEDOWN_EXT_AUTOLINK | HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_UNDERLINE | HOEDOWN_EXT_HIGHLIGHT | HOEDOWN_EXT_QUOTE | HOEDOWN_EXT_SUPERSCRIPT | HOEDOWN_EXT_MATH | HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_SPACE_HEADERS | HOEDOWN_EXT_MATH_EXPLICIT | HOEDOWN_EXT_HTML5_BLOCKS | HOEDOWN_EXT_NO_INTRA_UNDERLINE_EMPHASIS | HOEDOWN_EXT_DISABLE_INDENTED_CODE | HOEDOWN_EXT_SPECIAL_ATTRIBUTE | HOEDOWN_EXT_SCRIPT_TAGS | HOEDOWN_EXT_META_BLOCK; |
71 | 10.7k | opt.max_nesting = DEF_MAX_NESTING; |
72 | 10.7k | opt.link_attributes = 0; |
73 | | |
74 | | /* Read everything */ |
75 | 10.7k | ib = hoedown_buffer_new(opt.iunit); |
76 | 10.7k | hoedown_buffer_put(ib, data, size); |
77 | | |
78 | 10.7k | renderer = hoedown_html_renderer_new(opt.html_flags, opt.toc_level); |
79 | 10.7k | renderer_free = hoedown_html_renderer_free; |
80 | | |
81 | | /* Perform Markdown rendering */ |
82 | 10.7k | ob = hoedown_buffer_new(opt.ounit); |
83 | 10.7k | meta = hoedown_buffer_new(opt.ounit); |
84 | 10.7k | document = hoedown_document_new(renderer, opt.extensions, opt.max_nesting, opt.attr_activation, NULL, meta); |
85 | | |
86 | 10.7k | hoedown_html_renderer_state *state; |
87 | 10.7k | state = (hoedown_html_renderer_state *)renderer->opaque; |
88 | | |
89 | 10.7k | hoedown_document_render(document, ob, ib->data, ib->size); |
90 | | |
91 | | /* Cleanup */ |
92 | 10.7k | hoedown_buffer_free(ib); |
93 | 10.7k | hoedown_document_free(document); |
94 | 10.7k | renderer_free(renderer); |
95 | | |
96 | | /* Write the result to stdout */ |
97 | | // (void)fwrite(ob->data, 1, ob->size, stdout); |
98 | 10.7k | hoedown_buffer_free(ob); |
99 | | |
100 | 10.7k | hoedown_buffer_free(meta); |
101 | | |
102 | 10.7k | return 0; |
103 | 10.7k | } |