Coverage Report

Created: 2025-06-13 06:37

/src/w3m/fuzz/fuzz-conv.c
Line
Count
Source (jump to first uncovered line)
1
#include <stdint.h>
2
#include <stdlib.h>
3
#include <gc.h>
4
#include "wc.h"
5
#include "wtf.h"
6
7
0
static void *die_oom(size_t bytes) {
8
0
    fprintf(stderr, "Out of memory: %lu bytes unavailable!\n", (unsigned long)bytes);
9
0
    exit(1);
10
0
}
11
12
12.2k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){
13
12.2k
    static int init_done = 0;
14
15
12.2k
    if (!init_done) {
16
1
  setenv("GC_LARGE_ALLOC_WARN_INTERVAL", "30000", 1);
17
1
  GC_INIT();
18
1
#if (GC_VERSION_MAJOR>7) || ((GC_VERSION_MAJOR==7) && (GC_VERSION_MINOR>=2))
19
1
  GC_set_oom_fn(die_oom);
20
#else
21
  GC_oom_fn = die_oom;
22
#endif
23
1
#ifdef USE_M17N
24
1
#ifdef USE_UNICODE
25
1
  wtf_init(WC_CES_UTF_8, WC_CES_UTF_8);
26
#else
27
  wtf_init(WC_CES_EUC_JP, WC_CES_EUC_JP);
28
#endif
29
1
#endif
30
1
  init_done = 1;
31
1
    }
32
33
    /* Assume the data format is:
34
     *   <str1> \0 <str2> \0 <str3>
35
     */
36
12.2k
    const uint8_t *str1, *str2, *str3;
37
12.2k
    const uint8_t *p;
38
12.2k
    str1 = data;
39
12.2k
    p = memchr(str1, '\0', size);
40
12.2k
    if (p == NULL) return 0;
41
12.2k
    str2 = p + 1;
42
12.2k
    if (str2 >= data + size) return 0;
43
12.2k
    p = memchr(str2, '\0', data + size - str2);
44
12.2k
    if (p == NULL) return 0;
45
12.2k
    str3 = p + 1;
46
47
12.2k
    wc_ces old, from, to;
48
12.2k
    from = wc_guess_charset_short((char*)str1, 0);
49
12.2k
    to = wc_guess_charset_short((char*)str2, 0);
50
51
12.2k
    Str s = Strnew_charp_n((char*)str3, data + size - str3);
52
12.2k
    wc_Str_conv_with_detect(s, &from, from, to);
53
12.2k
    Strfree(s);
54
55
12.2k
    return 0;
56
12.2k
}