Coverage Report

Created: 2025-07-12 06:20

/src/oss-fuzz-example/char_lib.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2022 Ada Logics ltd.
2
 *
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License.
5
 * You may obtain a copy of the License at
6
 *
7
 *    http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 * See the License for the specific language governing permissions and
13
 * limitations under the License.
14
 */
15
#include <stdlib.h>
16
#include <stdio.h>
17
#include <string.h>
18
19
// Count the number of lowercase letters
20
// input must be a null-terminated string.
21
0
int count_lowercase_letters(char *input) {
22
0
  int length = 0;
23
0
  int lowercase_letters = 0;
24
25
0
  while (1) {
26
0
    if (input[length] == '\0') {
27
0
      break;
28
0
    }
29
0
    length++;
30
0
  }
31
  
32
0
  if (length == 0) {
33
0
    return 0;
34
0
  }
35
36
0
  for (int i = 0; i < length; i++) {
37
0
    if (input[i] >= 0x61 && input[i] <= 0x7a) {
38
0
      lowercase_letters++;
39
0
    }
40
0
  }
41
42
0
  if (lowercase_letters == 42) {
43
0
    printf("wooo\n");
44
0
  }
45
0
  if (lowercase_letters == 0x42) {
46
0
    printf("WOOO!\n");
47
0
  }
48
49
0
  return lowercase_letters;
50
0
}
51
52
61
int get_the_right_character(char *input, int idx) {
53
    // we can't read anything under idx.
54
61
    if (strlen(input) < 40) {
55
11
        return -1;
56
11
    }
57
58
50
    char c = input[idx];
59
50
    if (c == 'X') {
60
2
        return 1;
61
2
    }
62
48
    return -1;
63
50
}
64
65
78
int read_key_figures(char *input, size_t half_length) {
66
78
    if (half_length < 10) {
67
17
        return -1;
68
17
    }
69
70
    // We know half_length is under 10, so we can double it no problem.
71
61
    half_length += half_length;
72
61
    return get_the_right_character(input, half_length);
73
78
}
74
75
285
int parse_complex_format(char *input) {
76
285
    size_t length = strlen(input);
77
285
    if (length < 8) {
78
5
        return -1;
79
5
    }
80
81
280
    if (input[0] != 'F') {
82
12
        return -1;
83
12
    }
84
268
    if (input[1] != 'u') {
85
12
        return -1;
86
12
    }
87
256
    if (input[2] != 'z') {
88
11
        return -1;
89
11
    }
90
245
    if (input[3] != 'z') {
91
10
        return -1;
92
10
    }
93
94
235
    int sum = 0;
95
10.4M
    for (int i = 0; i < length; i++) {
96
10.4M
        if (input[i] > 0x20) {
97
4.48M
            sum += 1;
98
4.48M
        }
99
10.4M
    }
100
101
235
    if (sum < 20) {
102
78
        return read_key_figures(input, length/2);
103
78
    }
104
157
    else {
105
157
        if (sum > 40) {
106
147
            int *magic_ptr = (int*)input;
107
147
            int magic_val1 = magic_ptr[8];
108
147
            int magic_val2 = magic_ptr[9];
109
147
            if (magic_val1 == 0x41424344  && magic_val2 == 0x5b5d5b5d) {
110
1
                return 1;
111
1
            }
112
147
        }
113
157
    }
114
156
    return -1;
115
235
}
116
117
0
int parse_complex_format_second(char *input) {
118
0
    size_t length = strlen(input);
119
0
    if (length < 8) {
120
0
        return -1;
121
0
    }
122
123
0
    if (input[0] != 'F') {
124
0
        return -1;
125
0
    }
126
0
    if (input[1] != 'u') {
127
0
        return -1;
128
0
    }
129
0
    if (input[2] != 'z') {
130
0
        return -1;
131
0
    }
132
0
    if (input[3] != 'z') {
133
0
        return -1;
134
0
    }
135
136
0
    int sum = 0;
137
0
    for (int i = 0; i < length; i++) {
138
0
        if (input[i] > 0x20) {
139
0
            sum += 1;
140
0
        }
141
0
    }
142
143
0
    if (sum < 20) {
144
0
        return read_key_figures(input, (int)((length / 2) -1) );
145
0
    }
146
0
    else {
147
0
        if (sum > 40) {
148
0
            int *magic_ptr = (int*)input;
149
0
            int magic_val1 = magic_ptr[8];
150
0
            int magic_val2 = magic_ptr[9];
151
0
            if (magic_val1 == 0x41424344  && magic_val2 == 0x5b5d5b5d) {
152
0
                return 1;
153
0
            }
154
0
        }
155
0
    }
156
0
    return -1;
157
0
}