Coverage Report

Created: 2023-09-25 06:56

/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
29
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){
13
29
    static int init_done = 0;
14
15
29
    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
29
    const uint8_t *str1, *str2, *str3;
37
29
    const uint8_t *p;
38
29
    str1 = data;
39
29
    p = memchr(str1, '\0', size);
40
29
    if (p == NULL) return 0;
41
29
    str2 = p + 1;
42
29
    if (str2 >= data + size) return 0;
43
29
    p = memchr(str2, '\0', data + size - str2);
44
29
    if (p == NULL) return 0;
45
29
    str3 = p + 1;
46
47
29
    wc_ces old, from, to;
48
29
    from = wc_guess_charset_short((char*)str1, 0);
49
29
    to = wc_guess_charset_short((char*)str2, 0);
50
51
29
    Str s = Strnew_charp_n((char*)str3, data + size - str3);
52
29
    wc_Str_conv_with_detect(s, &from, from, to);
53
29
    Strfree(s);
54
55
29
    return 0;
56
29
}