Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvshadow/ossfuzz/store_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libvshadow store 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_libvshadow.h"
31
32
#if !defined( LIBVSHADOW_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
LIBVSHADOW_EXTERN \
38
int libvshadow_volume_open_file_io_handle(
39
     libvshadow_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libvshadow_error_t **error );
43
44
#endif /* !defined( LIBVSHADOW_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
2.39k
{
50
2.39k
  uint8_t buffer[ 512 ];
51
2.39k
  uint8_t guid[ 16 ];
52
53
2.39k
  libbfio_handle_t *file_io_handle = NULL;
54
2.39k
  libvshadow_store_t *store        = NULL;
55
2.39k
  libvshadow_volume_t *volume      = NULL;
56
2.39k
  off64_t volume_offset            = 0;
57
2.39k
  size64_t volume_size             = 0;
58
2.39k
  uint64_t value_64bit             = 0;
59
2.39k
  uint32_t value_32bit             = 0;
60
2.39k
  int number_of_blocks             = 0;
61
2.39k
  int number_of_stores             = 0;
62
2.39k
  int read_iterator                = 0;
63
64
2.39k
  if( libbfio_memory_range_initialize(
65
2.39k
       &file_io_handle,
66
2.39k
       NULL ) != 1 )
67
0
  {
68
0
    return( 0 );
69
0
  }
70
2.39k
  if( libbfio_memory_range_set(
71
2.39k
       file_io_handle,
72
2.39k
       (uint8_t *) data,
73
2.39k
       size,
74
2.39k
       NULL ) != 1 )
75
0
  {
76
0
    goto on_error_libbfio;
77
0
  }
78
2.39k
  if( libvshadow_volume_initialize(
79
2.39k
       &volume,
80
2.39k
       NULL ) != 1 )
81
0
  {
82
0
    goto on_error_libbfio;
83
0
  }
84
2.39k
  if( libvshadow_volume_open_file_io_handle(
85
2.39k
       volume,
86
2.39k
       file_io_handle,
87
2.39k
       LIBVSHADOW_OPEN_READ,
88
2.39k
       NULL ) != 1 )
89
1.86k
  {
90
1.86k
    goto on_error_libvshadow_volume;
91
1.86k
  }
92
532
  if( libvshadow_volume_get_number_of_stores(
93
532
       volume,
94
532
       &number_of_stores,
95
532
       NULL ) != 1 )
96
0
  {
97
0
    goto on_error_libvshadow_volume;
98
0
  }
99
532
  if( number_of_stores > 0 )
100
464
  {
101
464
    if( libvshadow_volume_get_store_identifier(
102
464
         volume,
103
464
         0,
104
464
         guid,
105
464
         16,
106
464
         NULL ) != 1 )
107
0
    {
108
0
      goto on_error_libvshadow_volume;
109
0
    }
110
464
    if( libvshadow_volume_get_store(
111
464
         volume,
112
464
         0,
113
464
         &store,
114
464
         NULL ) != 1 )
115
0
    {
116
0
      goto on_error_libvshadow_volume;
117
0
    }
118
464
    if( libvshadow_store_get_identifier(
119
464
         store,
120
464
         guid,
121
464
         16,
122
464
         NULL ) != 1 )
123
0
    {
124
0
      goto on_error_libvshadow_store;
125
0
    }
126
464
    if( libvshadow_store_get_creation_time(
127
464
         store,
128
464
         &value_64bit,
129
464
         NULL ) != 1 )
130
0
    {
131
0
      goto on_error_libvshadow_store;
132
0
    }
133
464
    if( libvshadow_store_get_copy_identifier(
134
464
         store,
135
464
         guid,
136
464
         16,
137
464
         NULL ) != 1 )
138
19
    {
139
19
      goto on_error_libvshadow_store;
140
19
    }
141
445
    if( libvshadow_store_get_copy_set_identifier(
142
445
         store,
143
445
         guid,
144
445
         16,
145
445
         NULL ) != 1 )
146
0
    {
147
0
      goto on_error_libvshadow_store;
148
0
    }
149
445
    if( libvshadow_store_get_attribute_flags(
150
445
         store,
151
445
         &value_32bit,
152
445
         NULL ) != 1 )
153
0
    {
154
0
      goto on_error_libvshadow_store;
155
0
    }
156
445
    if( libvshadow_store_get_number_of_blocks(
157
445
         store,
158
445
         &number_of_blocks,
159
445
         NULL ) != 1 )
160
299
    {
161
299
      goto on_error_libvshadow_store;
162
299
    }
163
146
    if( libvshadow_store_get_size(
164
146
         store,
165
146
         &value_64bit,
166
146
         NULL ) != 1 )
167
0
    {
168
0
      goto on_error_libvshadow_store;
169
0
    }
170
146
    if( libvshadow_store_get_volume_size(
171
146
         store,
172
146
         &volume_size,
173
146
         NULL ) != 1 )
174
0
    {
175
0
      goto on_error_libvshadow_store;
176
0
    }
177
146
    for( read_iterator = 0;
178
6.95k
         read_iterator < 128;
179
6.81k
         read_iterator++ )
180
6.91k
    {
181
6.91k
      if( volume_offset >= volume_size )
182
22
      {
183
22
        break;
184
22
      }
185
6.88k
      if( libvshadow_store_read_buffer_at_offset(
186
6.88k
           store,
187
6.88k
           buffer,
188
6.88k
           497,
189
6.88k
           volume_offset,
190
6.88k
           NULL ) == -1 )
191
78
      {
192
78
        goto on_error_libvshadow_store;
193
78
      }
194
6.81k
      volume_offset += 497;
195
6.81k
    }
196
464
on_error_libvshadow_store:
197
464
    libvshadow_store_free(
198
464
     &store,
199
464
     NULL );
200
464
  }
201
532
  libvshadow_volume_close(
202
532
   volume,
203
532
   NULL );
204
205
2.39k
on_error_libvshadow_volume:
206
2.39k
  libvshadow_volume_free(
207
2.39k
   &volume,
208
2.39k
   NULL );
209
210
2.39k
on_error_libbfio:
211
2.39k
  libbfio_handle_free(
212
2.39k
   &file_io_handle,
213
2.39k
   NULL );
214
215
2.39k
  return( 0 );
216
2.39k
}
217
218
} /* extern "C" */
219