summaryrefslogtreecommitdiff
path: root/cmark/fuzz
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:41:54 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:41:54 +0300
commit3d2121f5d6555744ce5aa502088fc2b34dc26d38 (patch)
tree53f42c08746171878b57f5b6ffe1eb841da9d45d /cmark/fuzz
parent6bf7c5ce92ff6237c0b17c332873805018812b40 (diff)
parent64efa3b3b3d35f2ffb604b57a8a9c89047cb420b (diff)
downloadProject-Tick-3d2121f5d6555744ce5aa502088fc2b34dc26d38.tar.gz
Project-Tick-3d2121f5d6555744ce5aa502088fc2b34dc26d38.zip
Add 'cmark/' from commit '64efa3b3b3d35f2ffb604b57a8a9c89047cb420b'
git-subtree-dir: cmark git-subtree-mainline: 6bf7c5ce92ff6237c0b17c332873805018812b40 git-subtree-split: 64efa3b3b3d35f2ffb604b57a8a9c89047cb420b
Diffstat (limited to 'cmark/fuzz')
-rw-r--r--cmark/fuzz/CMakeLists.txt3
-rw-r--r--cmark/fuzz/afl_test_cases/test.md36
-rw-r--r--cmark/fuzz/cmark-fuzz.c75
-rw-r--r--cmark/fuzz/dictionary49
4 files changed, 163 insertions, 0 deletions
diff --git a/cmark/fuzz/CMakeLists.txt b/cmark/fuzz/CMakeLists.txt
new file mode 100644
index 0000000000..8ffecef4e0
--- /dev/null
+++ b/cmark/fuzz/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_executable(cmark-fuzz cmark-fuzz.c)
+cmark_add_compile_options(cmark-fuzz)
+target_link_libraries(cmark-fuzz cmark)
diff --git a/cmark/fuzz/afl_test_cases/test.md b/cmark/fuzz/afl_test_cases/test.md
new file mode 100644
index 0000000000..27eee009c7
--- /dev/null
+++ b/cmark/fuzz/afl_test_cases/test.md
@@ -0,0 +1,36 @@
+# H1
+
+H2
+--
+
+t ☺
+*b* **em** `c`
+&ge;\&\
+\_e\_
+
+4) I1
+
+5) I2
+ > [l](/u "t")
+ >
+ > - [f]
+ > - ![a](/u "t")
+ >
+ >> <ftp://hh>
+ >> <u@hh>
+
+~~~ l☺
+cb
+~~~
+
+ c1
+ c2
+
+***
+
+<div>
+<b>x</b>
+</div>
+
+[f]: /u "t"
+
diff --git a/cmark/fuzz/cmark-fuzz.c b/cmark/fuzz/cmark-fuzz.c
new file mode 100644
index 0000000000..74e72013e2
--- /dev/null
+++ b/cmark/fuzz/cmark-fuzz.c
@@ -0,0 +1,75 @@
+/* for fmemopen */
+#define _POSIX_C_SOURCE 200809L
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "cmark.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ struct __attribute__((packed)) {
+ int options;
+ int width;
+ } fuzz_config;
+
+ if (size >= sizeof(fuzz_config)) {
+ /* The beginning of `data` is treated as fuzzer configuration */
+ memcpy(&fuzz_config, data, sizeof(fuzz_config));
+ int options = fuzz_config.options;
+
+ /* Mask off valid option bits */
+ options &= (CMARK_OPT_SOURCEPOS | CMARK_OPT_HARDBREAKS | CMARK_OPT_UNSAFE | CMARK_OPT_NOBREAKS | CMARK_OPT_NORMALIZE | CMARK_OPT_VALIDATE_UTF8 | CMARK_OPT_SMART);
+
+ /* Remainder of input is the markdown */
+ const char *markdown = (const char *)(data + sizeof(fuzz_config));
+ size_t markdown_size = size - sizeof(fuzz_config);
+ cmark_node *doc = NULL;
+
+ /* Use upper bits of options to select parsing mode */
+ switch (((unsigned) fuzz_config.options >> 30) & 3) {
+ case 0:
+ doc = cmark_parse_document(markdown, markdown_size, options);
+ break;
+
+ case 1:
+ if (markdown_size > 0) {
+ FILE *file = fmemopen((void *) markdown, markdown_size, "r");
+ doc = cmark_parse_file(file, options);
+ fclose(file);
+ }
+ break;
+
+ case 2: {
+ size_t block_max = 20;
+ cmark_parser *parser = cmark_parser_new(options);
+
+ while (markdown_size > 0) {
+ size_t block_size = markdown_size > block_max ? block_max : markdown_size;
+ cmark_parser_feed(parser, markdown, block_size);
+ markdown += block_size;
+ markdown_size -= block_size;
+ }
+
+ doc = cmark_parser_finish(parser);
+ cmark_parser_free(parser);
+ break;
+ }
+
+ case 3:
+ free(cmark_markdown_to_html(markdown, markdown_size, options));
+ break;
+ }
+
+ if (doc != NULL) {
+ free(cmark_render_commonmark(doc, options, fuzz_config.width));
+ free(cmark_render_html(doc, options));
+ free(cmark_render_latex(doc, options, fuzz_config.width));
+ free(cmark_render_man(doc, options, fuzz_config.width));
+ free(cmark_render_xml(doc, options));
+
+ cmark_node_free(doc);
+ }
+ }
+ return 0;
+}
diff --git a/cmark/fuzz/dictionary b/cmark/fuzz/dictionary
new file mode 100644
index 0000000000..b06783c94e
--- /dev/null
+++ b/cmark/fuzz/dictionary
@@ -0,0 +1,49 @@
+asterisk="*"
+attr_generic=" a=\"1\""
+attr_href=" href=\"1\""
+attr_xml_lang=" xml:lang=\"1\""
+attr_xmlns=" xmlns=\"1\""
+backslash="\\"
+backtick="`"
+colon=":"
+dashes="---"
+double_quote="\""
+entity_builtin="&lt;"
+entity_decimal="&#1;"
+entity_external="&a;"
+entity_hex="&#x1;"
+equals="==="
+exclamation="!"
+greater_than=">"
+hash="#"
+hyphen="-"
+indent=" "
+left_bracket="["
+left_paren="("
+less_than="<"
+plus="+"
+right_bracket="]"
+right_paren=")"
+single_quote="'"
+string_any="ANY"
+string_brackets="[]"
+string_cdata="CDATA"
+string_dashes="--"
+string_empty_dblquotes="\"\""
+string_empty_quotes="''"
+string_idrefs="IDREFS"
+string_parentheses="()"
+string_pcdata="#PCDATA"
+tag_cdata="<![CDATA["
+tag_close="</a>"
+tag_doctype="<!DOCTYPE"
+tag_element="<!ELEMENT"
+tag_entity="<!ENTITY"
+tag_notation="<!NOTATION"
+tag_open="<a>"
+tag_open_close="<a />"
+tag_open_exclamation="<!"
+tag_open_q="<?"
+tag_sq2_close="]]>"
+tag_xml_q="<?xml?>"
+underscore="_"