Coverage Report

Created: 2026-08-31 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfshfs/ossfuzz/file_entry_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfshfs file_entry type
3
 *
4
 * Copyright (C) 2009-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_libfshfs.h"
31
32
#if !defined( LIBFSHFS_HAVE_BFIO )
33
34
/* Opens a volume using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBFSHFS_EXTERN \
38
int libfshfs_volume_open_file_io_handle(
39
     libfshfs_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libfshfs_error_t **error );
43
44
#endif /* !defined( LIBFSHFS_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
7.72k
{
50
7.72k
  uint8_t string_value[ 64 ];
51
52
7.72k
  libbfio_handle_t *file_io_handle      = NULL;
53
7.72k
  libfshfs_file_entry_t *root_directory = NULL;
54
7.72k
  libfshfs_file_entry_t *sub_file_entry = NULL;
55
7.72k
  libfshfs_volume_t *volume             = NULL;
56
7.72k
  size64_t file_size                    = 0;
57
7.72k
  size_t string_size                    = 0;
58
7.72k
  off64_t file_offset                   = 0;
59
7.72k
  uint32_t hfs_time                     = 0;
60
7.72k
  uint32_t major_device_number          = 0;
61
7.72k
  uint32_t minor_device_number          = 0;
62
7.72k
  uint32_t value_32bit                  = 0;
63
7.72k
  int32_t posix_time                    = 0;
64
7.72k
  uint16_t value_16bit                  = 0;
65
7.72k
  int number_of_extents                 = 0;
66
7.72k
  int number_of_sub_file_entries        = 0;
67
7.72k
  int result                            = 0;
68
69
7.72k
  if( libbfio_memory_range_initialize(
70
7.72k
       &file_io_handle,
71
7.72k
       NULL ) != 1 )
72
0
  {
73
0
    return( 0 );
74
0
  }
75
7.72k
  if( libbfio_memory_range_set(
76
7.72k
       file_io_handle,
77
7.72k
       (uint8_t *) data,
78
7.72k
       size,
79
7.72k
       NULL ) != 1 )
80
0
  {
81
0
    goto on_error_libbfio;
82
0
  }
83
7.72k
  if( libfshfs_volume_initialize(
84
7.72k
       &volume,
85
7.72k
       NULL ) != 1 )
86
0
  {
87
0
    goto on_error_libbfio;
88
0
  }
89
7.72k
  if( libfshfs_volume_open_file_io_handle(
90
7.72k
       volume,
91
7.72k
       file_io_handle,
92
7.72k
       LIBFSHFS_OPEN_READ,
93
7.72k
       NULL ) != 1 )
94
1.68k
  {
95
1.68k
    goto on_error_libfshfs_volume;
96
1.68k
  }
97
6.04k
  if( libfshfs_volume_get_root_directory(
98
6.04k
       volume,
99
6.04k
       &root_directory,
100
6.04k
       NULL ) == 1 )
101
3.91k
  {
102
3.91k
    if( libfshfs_file_entry_get_number_of_sub_file_entries(
103
3.91k
         root_directory,
104
3.91k
         &number_of_sub_file_entries,
105
3.91k
         NULL ) != 1 )
106
1.18k
    {
107
1.18k
      goto on_error_libfshfs_root_directory;
108
1.18k
    }
109
2.73k
    if( number_of_sub_file_entries > 0 )
110
2.47k
    {
111
2.47k
      result = libfshfs_file_entry_get_sub_file_entry_by_index(
112
2.47k
                root_directory,
113
2.47k
                0,
114
2.47k
                &sub_file_entry,
115
2.47k
                NULL );
116
117
2.47k
      if( result != -1 )
118
1.97k
      {
119
1.97k
        libfshfs_file_entry_get_identifier(
120
1.97k
         sub_file_entry,
121
1.97k
         &value_32bit,
122
1.97k
         NULL );
123
124
1.97k
        libfshfs_file_entry_get_parent_identifier(
125
1.97k
         sub_file_entry,
126
1.97k
         &value_32bit,
127
1.97k
         NULL );
128
129
1.97k
        libfshfs_file_entry_get_link_identifier(
130
1.97k
         sub_file_entry,
131
1.97k
         &value_32bit,
132
1.97k
         NULL );
133
134
1.97k
        libfshfs_file_entry_get_creation_time(
135
1.97k
         sub_file_entry,
136
1.97k
         &hfs_time,
137
1.97k
         NULL );
138
139
1.97k
        libfshfs_file_entry_get_access_time(
140
1.97k
         sub_file_entry,
141
1.97k
         &hfs_time,
142
1.97k
         NULL );
143
144
1.97k
        libfshfs_file_entry_get_backup_time(
145
1.97k
         sub_file_entry,
146
1.97k
         &hfs_time,
147
1.97k
         NULL );
148
149
1.97k
        libfshfs_file_entry_get_added_time(
150
1.97k
         sub_file_entry,
151
1.97k
         &posix_time,
152
1.97k
         NULL );
153
154
1.97k
        libfshfs_file_entry_get_file_mode(
155
1.97k
         sub_file_entry,
156
1.97k
         &value_16bit,
157
1.97k
         NULL );
158
159
1.97k
        libfshfs_file_entry_get_number_of_links(
160
1.97k
         sub_file_entry,
161
1.97k
         &value_32bit,
162
1.97k
         NULL );
163
164
1.97k
        libfshfs_file_entry_get_owner_identifier(
165
1.97k
         sub_file_entry,
166
1.97k
         &value_32bit,
167
1.97k
         NULL );
168
169
1.97k
        libfshfs_file_entry_get_group_identifier(
170
1.97k
         sub_file_entry,
171
1.97k
         &value_32bit,
172
1.97k
         NULL );
173
174
1.97k
        libfshfs_file_entry_get_device_identifier(
175
1.97k
         sub_file_entry,
176
1.97k
         &value_32bit,
177
1.97k
         NULL );
178
179
1.97k
        libfshfs_file_entry_get_device_number(
180
1.97k
         sub_file_entry,
181
1.97k
         &major_device_number,
182
1.97k
         &minor_device_number,
183
1.97k
         NULL );
184
185
1.97k
        libfshfs_file_entry_get_utf8_name_size(
186
1.97k
         sub_file_entry,
187
1.97k
         &string_size,
188
1.97k
         NULL );
189
190
1.97k
        libfshfs_file_entry_get_utf8_name(
191
1.97k
         sub_file_entry,
192
1.97k
         string_value,
193
1.97k
         64,
194
1.97k
         NULL );
195
196
1.97k
        libfshfs_file_entry_get_utf8_symbolic_link_target_size(
197
1.97k
         sub_file_entry,
198
1.97k
         &string_size,
199
1.97k
         NULL );
200
201
1.97k
        libfshfs_file_entry_get_utf8_symbolic_link_target(
202
1.97k
         sub_file_entry,
203
1.97k
         string_value,
204
1.97k
         64,
205
1.97k
         NULL );
206
207
1.97k
        libfshfs_file_entry_has_resource_fork(
208
1.97k
         sub_file_entry,
209
1.97k
         NULL );
210
211
1.97k
        libfshfs_file_entry_get_offset(
212
1.97k
         sub_file_entry,
213
1.97k
         &file_offset,
214
1.97k
         NULL );
215
216
1.97k
        libfshfs_file_entry_get_size(
217
1.97k
         sub_file_entry,
218
1.97k
         &file_size,
219
1.97k
         NULL );
220
221
1.97k
        libfshfs_file_entry_get_number_of_extents(
222
1.97k
         sub_file_entry,
223
1.97k
         &number_of_extents,
224
1.97k
         NULL );
225
1.97k
      }
226
2.47k
      libfshfs_file_entry_free(
227
2.47k
       &sub_file_entry,
228
2.47k
       NULL );
229
2.47k
    }
230
3.91k
on_error_libfshfs_root_directory:
231
3.91k
    libfshfs_file_entry_free(
232
3.91k
     &root_directory,
233
3.91k
     NULL );
234
3.91k
  }
235
6.04k
  libfshfs_volume_close(
236
6.04k
   volume,
237
6.04k
   NULL );
238
239
7.72k
on_error_libfshfs_volume:
240
7.72k
  libfshfs_volume_free(
241
7.72k
   &volume,
242
7.72k
   NULL );
243
244
7.72k
on_error_libbfio:
245
7.72k
  libbfio_handle_free(
246
7.72k
   &file_io_handle,
247
7.72k
   NULL );
248
249
7.72k
  return( 0 );
250
7.72k
}
251
252
} /* extern "C" */
253