Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libesedb/ossfuzz/column_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libesedb column type
3
 *
4
 * Copyright (C) 2011-2026, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <stddef.h>
23
#include <stdint.h>
24
25
/* Note that some of the OSS-Fuzz engines use C++
26
 */
27
extern "C" {
28
29
#include "ossfuzz_libbfio.h"
30
#include "ossfuzz_libesedb.h"
31
32
#if !defined( LIBESEDB_HAVE_BFIO )
33
34
/* Opens a file using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBESEDB_EXTERN \
38
int libesedb_file_open_file_io_handle(
39
      libesedb_file_t *file,
40
      libbfio_handle_t *file_io_handle,
41
      int access_flags,
42
      libesedb_error_t **error );
43
44
#endif /* !defined( LIBESEDB_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
      const uint8_t *data,
48
      size_t size )
49
1.64k
{
50
1.64k
  uint8_t utf8_name[ 64 ];
51
1.64k
  uint16_t utf16_name[ 32 ];
52
53
1.64k
  libbfio_handle_t *file_io_handle = NULL;
54
1.64k
  libesedb_column_t *column        = NULL;
55
1.64k
  libesedb_file_t *file            = NULL;
56
1.64k
  libesedb_table_t *table          = NULL;
57
1.64k
  size_t utf8_name_size            = 0;
58
1.64k
  size_t utf16_name_size           = 0;
59
1.64k
  uint32_t column_type             = 0;
60
1.64k
  uint32_t identifier              = 0;
61
1.64k
  int number_of_columns            = 0;
62
1.64k
  int number_of_tables             = 0;
63
64
1.64k
  if( libbfio_memory_range_initialize(
65
1.64k
       &file_io_handle,
66
1.64k
       NULL ) != 1 )
67
0
  {
68
0
    return( 0 );
69
0
  }
70
1.64k
  if( libbfio_memory_range_set(
71
1.64k
       file_io_handle,
72
1.64k
       (uint8_t *) data,
73
1.64k
       size,
74
1.64k
       NULL ) != 1 )
75
0
  {
76
0
    goto on_error_libbfio;
77
0
  }
78
1.64k
  if( libesedb_file_initialize(
79
1.64k
       &file,
80
1.64k
       NULL ) != 1 )
81
0
  {
82
0
    goto on_error_libbfio;
83
0
  }
84
1.64k
  if( libesedb_file_open_file_io_handle(
85
1.64k
       file,
86
1.64k
       file_io_handle,
87
1.64k
       LIBESEDB_OPEN_READ,
88
1.64k
       NULL ) != 1 )
89
1.36k
  {
90
1.36k
    goto on_error_libesedb_file;
91
1.36k
  }
92
277
  if( libesedb_file_get_number_of_tables(
93
277
       file,
94
277
       &number_of_tables,
95
277
       NULL ) != 1 )
96
0
  {
97
0
    goto on_error_libesedb_file;
98
0
  }
99
277
  if( number_of_tables > 0 )
100
215
  {
101
215
    if( libesedb_file_get_table(
102
215
         file,
103
215
         0,
104
215
         &table,
105
215
         NULL ) != 1 )
106
171
    {
107
171
      goto on_error_libesedb_file;
108
171
    }
109
44
    if( libesedb_table_get_number_of_columns(
110
44
         table,
111
44
         &number_of_columns,
112
44
         0,
113
44
         NULL ) != 1 )
114
0
    {
115
0
      goto on_error_libesedb_table;
116
0
    }
117
44
    if( number_of_columns > 0 )
118
39
    {
119
39
      if( libesedb_table_get_column(
120
39
           table,
121
39
           0,
122
39
           &column,
123
39
           0,
124
39
           NULL ) != 1 )
125
0
      {
126
0
        goto on_error_libesedb_table;
127
0
      }
128
39
      if( libesedb_column_get_identifier(
129
39
           column,
130
39
           &identifier,
131
39
           NULL ) != 1 )
132
0
      {
133
0
        goto on_error_libesedb_column;
134
0
      }
135
39
      if( libesedb_column_get_type(
136
39
           column,
137
39
           &column_type,
138
39
           NULL ) != 1 )
139
0
      {
140
0
        goto on_error_libesedb_column;
141
0
      }
142
39
      if( libesedb_column_get_utf8_name_size(
143
39
           column,
144
39
           &utf8_name_size,
145
39
           NULL ) != 1 )
146
2
      {
147
2
        goto on_error_libesedb_column;
148
2
      }
149
37
      if( utf8_name_size > 0 )
150
37
      {
151
37
        if( libesedb_column_get_utf8_name(
152
37
             column,
153
37
             utf8_name,
154
37
             64,
155
37
             NULL ) != 1 )
156
11
        {
157
11
          goto on_error_libesedb_column;
158
11
        }
159
37
      }
160
26
      if( libesedb_column_get_utf16_name_size(
161
26
           column,
162
26
           &utf16_name_size,
163
26
           NULL ) != 1 )
164
0
      {
165
0
        goto on_error_libesedb_column;
166
0
      }
167
26
      if( utf16_name_size > 0 )
168
26
      {
169
26
        if( libesedb_column_get_utf16_name(
170
26
             column,
171
26
             utf16_name,
172
26
             32,
173
26
             NULL ) != 1 )
174
6
        {
175
6
          goto on_error_libesedb_column;
176
6
        }
177
26
      }
178
39
on_error_libesedb_column:
179
39
      libesedb_column_free(
180
39
       &column,
181
39
       NULL );
182
39
    }
183
44
on_error_libesedb_table:
184
44
    libesedb_table_free(
185
44
     &table,
186
44
     NULL );
187
44
  }
188
106
  libesedb_file_close(
189
106
   file,
190
106
   NULL );
191
192
1.64k
on_error_libesedb_file:
193
1.64k
  libesedb_file_free(
194
1.64k
   &file,
195
1.64k
   NULL );
196
197
1.64k
on_error_libbfio:
198
1.64k
  libbfio_handle_free(
199
1.64k
   &file_io_handle,
200
1.64k
   NULL );
201
202
1.64k
  return( 0 );
203
1.64k
}
204
205
} /* extern "C" */