MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / fuzz_extract

Function fuzz_extract

tests/fuzz/cbm_fuzz.c:77–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77static void fuzz_extract(const uint8_t *data, size_t size) {
78 size_t scan = size < FUZZ_NAME_MAX ? size : FUZZ_NAME_MAX;
79 const uint8_t *nl = memchr(data, '\n', scan);
80 if (!nl || nl == data) {
81 return;
82 }
83 size_t name_len = (size_t)(nl - data);
84 char name[FUZZ_NAME_MAX + FUZZ_NUL];
85 memcpy(name, data, name_len);
86 name[name_len] = '\0';
87 CBMLanguage lang = cbm_language_for_filename(name);
88 if ((int)lang < 0 || lang >= CBM_LANG_COUNT) {
89 return;
90 }
91 size_t src_len = size - name_len - FUZZ_NUL;
92 if (src_len > (size_t)INT32_MAX) {
93 return;
94 }
95 /* The pipeline hands extraction a file buffer with a terminator after
96 * source_len bytes, and parts of the LSP passes rely on it (strlen over the
97 * source). Fuzz the contract production honours, not a stricter one. */
98 char *source = malloc(src_len + FUZZ_NUL);
99 if (!source) {
100 return;
101 }
102 memcpy(source, nl + FUZZ_NUL, src_len);
103 source[src_len] = '\0';
104 CBMFileResult *r = cbm_extract_file(source, (int)src_len, lang, "fuzz", name,
105 FUZZ_EXTRACT_BUDGET_MICROS, NULL, NULL);
106 if (r) {
107 cbm_free_tree(r);
108 cbm_free_result(r);
109 }
110 free(source);
111}
112
113static void fuzz_cypher(const uint8_t *data, size_t size) {
114 char *query = malloc(size + FUZZ_NUL);

Callers 1

LLVMFuzzerTestOneInputFunction · 0.85

Calls 4

cbm_extract_fileFunction · 0.85
cbm_free_treeFunction · 0.85
cbm_free_resultFunction · 0.85

Tested by

no test coverage detected