Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfsntfs/ossfuzz/volume_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfsntfs volume type
3
 *
4
 * Copyright (C) 2010-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_libfsntfs.h"
31
32
#if !defined( LIBFSNTFS_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
LIBFSNTFS_EXTERN \
38
int libfsntfs_volume_open_file_io_handle(
39
      libfsntfs_volume_t *volume,
40
      libbfio_handle_t *file_io_handle,
41
      int access_flags,
42
      libfsntfs_error_t **error );
43
44
#endif /* !defined( LIBFSNTFS_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
      const uint8_t *data,
48
      size_t size )
49
3.83k
{
50
3.83k
  uint8_t utf8_string[ 64 ];
51
3.83k
  uint16_t utf16_string[ 32 ];
52
53
3.83k
  libbfio_handle_t *file_io_handle = NULL;
54
3.83k
  libfsntfs_volume_t *volume       = NULL;
55
3.83k
  uint64_t number_of_file_entries  = 0;
56
3.83k
  uint64_t serial_number           = 0;
57
3.83k
  size_t utf8_string_size          = 0;
58
3.83k
  size_t utf16_string_size         = 0;
59
3.83k
  uint32_t cluster_block_size      = 0;
60
3.83k
  uint32_t index_entry_size        = 0;
61
3.83k
  uint32_t mft_entry_size          = 0;
62
3.83k
  uint16_t bytes_per_sector        = 0;
63
3.83k
  uint16_t flags                   = 0;
64
3.83k
  uint8_t major_version            = 0;
65
3.83k
  uint8_t minor_version            = 0;
66
67
3.83k
  if( libbfio_memory_range_initialize(
68
3.83k
       &file_io_handle,
69
3.83k
       NULL ) != 1 )
70
0
  {
71
0
    return( 0 );
72
0
  }
73
3.83k
  if( libbfio_memory_range_set(
74
3.83k
       file_io_handle,
75
3.83k
       (uint8_t *) data,
76
3.83k
       size,
77
3.83k
       NULL ) != 1 )
78
0
  {
79
0
    goto on_error_libbfio;
80
0
  }
81
3.83k
  if( libfsntfs_volume_initialize(
82
3.83k
       &volume,
83
3.83k
       NULL ) != 1 )
84
0
  {
85
0
    goto on_error_libbfio;
86
0
  }
87
3.83k
  if( libfsntfs_volume_open_file_io_handle(
88
3.83k
       volume,
89
3.83k
       file_io_handle,
90
3.83k
       LIBFSNTFS_OPEN_READ,
91
3.83k
       NULL ) != 1 )
92
3.69k
  {
93
3.69k
    goto on_error_libfsntfs;
94
3.69k
  }
95
137
  if( libfsntfs_volume_has_bitlocker_drive_encryption(
96
137
       volume,
97
137
       NULL ) == -1 )
98
0
  {
99
0
    goto on_error_libfsntfs;
100
0
  }
101
137
  if( libfsntfs_volume_has_volume_shadow_snapshots(
102
137
       volume,
103
137
       NULL ) == -1 )
104
0
  {
105
0
    goto on_error_libfsntfs;
106
0
  }
107
137
  if( libfsntfs_volume_get_bytes_per_sector(
108
137
       volume,
109
137
       &bytes_per_sector,
110
137
       NULL ) != 1 )
111
0
  {
112
0
    goto on_error_libfsntfs;
113
0
  }
114
137
  if( libfsntfs_volume_get_cluster_block_size(
115
137
       volume,
116
137
       &cluster_block_size,
117
137
       NULL ) != 1 )
118
0
  {
119
0
    goto on_error_libfsntfs;
120
0
  }
121
137
  if( libfsntfs_volume_get_mft_entry_size(
122
137
       volume,
123
137
       &mft_entry_size,
124
137
       NULL ) != 1 )
125
0
  {
126
0
    goto on_error_libfsntfs;
127
0
  }
128
137
  if( libfsntfs_volume_get_index_entry_size(
129
137
       volume,
130
137
       &index_entry_size,
131
137
       NULL ) != 1 )
132
0
  {
133
0
    goto on_error_libfsntfs;
134
0
  }
135
137
  if( libfsntfs_volume_get_serial_number(
136
137
       volume,
137
137
       &serial_number,
138
137
       NULL ) != 1 )
139
0
  {
140
0
    goto on_error_libfsntfs;
141
0
  }
142
137
  if( libfsntfs_volume_get_utf8_name_size(
143
137
       volume,
144
137
       &utf8_string_size,
145
137
       NULL ) == -1 )
146
73
  {
147
73
    goto on_error_libfsntfs;
148
73
  }
149
64
  if( libfsntfs_volume_get_utf8_name(
150
64
       volume,
151
64
       utf8_string,
152
64
       64,
153
64
       NULL ) == -1 )
154
3
  {
155
3
    goto on_error_libfsntfs;
156
3
  }
157
61
  if( libfsntfs_volume_get_utf16_name_size(
158
61
       volume,
159
61
       &utf16_string_size,
160
61
       NULL ) == -1 )
161
0
  {
162
0
    goto on_error_libfsntfs;
163
0
  }
164
61
  if( libfsntfs_volume_get_utf16_name(
165
61
       volume,
166
61
       utf16_string,
167
61
       32,
168
61
       NULL ) == -1 )
169
2
  {
170
2
    goto on_error_libfsntfs;
171
2
  }
172
59
  if( libfsntfs_volume_get_version(
173
59
       volume,
174
59
       &major_version,
175
59
       &minor_version,
176
59
       NULL ) == -1 )
177
4
  {
178
4
    goto on_error_libfsntfs;
179
4
  }
180
55
  if( libfsntfs_volume_get_flags(
181
55
       volume,
182
55
       &flags,
183
55
       NULL ) == -1 )
184
0
  {
185
0
    goto on_error_libfsntfs;
186
0
  }
187
55
  if( libfsntfs_volume_get_number_of_file_entries(
188
55
       volume,
189
55
       &number_of_file_entries,
190
55
       NULL ) != 1 )
191
0
  {
192
0
    goto on_error_libfsntfs;
193
0
  }
194
55
  libfsntfs_volume_close(
195
55
   volume,
196
55
   NULL );
197
198
3.83k
on_error_libfsntfs:
199
3.83k
  libfsntfs_volume_free(
200
3.83k
   &volume,
201
3.83k
   NULL );
202
203
3.83k
on_error_libbfio:
204
3.83k
  libbfio_handle_free(
205
3.83k
   &file_io_handle,
206
3.83k
   NULL );
207
208
3.83k
  return( 0 );
209
3.83k
}
210
211
} /* extern "C" */