Coverage Report

Created: 2026-10-22 07:28

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.43k
{
50
2.43k
  uint8_t buffer[ 512 ];
51
2.43k
  uint8_t guid[ 16 ];
52
53
2.43k
  libbfio_handle_t *file_io_handle = NULL;
54
2.43k
  libvshadow_store_t *store        = NULL;
55
2.43k
  libvshadow_volume_t *volume      = NULL;
56
2.43k
  off64_t volume_offset            = 0;
57
2.43k
  size64_t volume_size             = 0;
58
2.43k
  uint64_t value_64bit             = 0;
59
2.43k
  uint32_t value_32bit             = 0;
60
2.43k
  int number_of_blocks             = 0;
61
2.43k
  int number_of_stores             = 0;
62
2.43k
  int read_iterator                = 0;
63
64
2.43k
  if( libbfio_memory_range_initialize(
65
2.43k
       &file_io_handle,
66
2.43k
       NULL ) != 1 )
67
0
  {
68
0
    return( 0 );
69
0
  }
70
2.43k
  if( libbfio_memory_range_set(
71
2.43k
       file_io_handle,
72
2.43k
       (uint8_t *) data,
73
2.43k
       size,
74
2.43k
       NULL ) != 1 )
75
0
  {
76
0
    goto on_error_libbfio;
77
0
  }
78
2.43k
  if( libvshadow_volume_initialize(
79
2.43k
       &volume,
80
2.43k
       NULL ) != 1 )
81
0
  {
82
0
    goto on_error_libbfio;
83
0
  }
84
2.43k
  if( libvshadow_volume_open_file_io_handle(
85
2.43k
       volume,
86
2.43k
       file_io_handle,
87
2.43k
       LIBVSHADOW_OPEN_READ,
88
2.43k
       NULL ) != 1 )
89
1.87k
  {
90
1.87k
    goto on_error_libvshadow_volume;
91
1.87k
  }
92
559
  if( libvshadow_volume_get_number_of_stores(
93
559
       volume,
94
559
       &number_of_stores,
95
559
       NULL ) != 1 )
96
0
  {
97
0
    goto on_error_libvshadow_volume;
98
0
  }
99
559
  if( number_of_stores > 0 )
100
493
  {
101
493
    if( libvshadow_volume_get_store_identifier(
102
493
         volume,
103
493
         0,
104
493
         guid,
105
493
         16,
106
493
         NULL ) != 1 )
107
0
    {
108
0
      goto on_error_libvshadow_volume;
109
0
    }
110
493
    if( libvshadow_volume_get_store(
111
493
         volume,
112
493
         0,
113
493
         &store,
114
493
         NULL ) != 1 )
115
0
    {
116
0
      goto on_error_libvshadow_volume;
117
0
    }
118
493
    if( libvshadow_store_get_identifier(
119
493
         store,
120
493
         guid,
121
493
         16,
122
493
         NULL ) != 1 )
123
0
    {
124
0
      goto on_error_libvshadow_store;
125
0
    }
126
493
    if( libvshadow_store_get_creation_time(
127
493
         store,
128
493
         &value_64bit,
129
493
         NULL ) != 1 )
130
0
    {
131
0
      goto on_error_libvshadow_store;
132
0
    }
133
493
    if( libvshadow_store_get_copy_identifier(
134
493
         store,
135
493
         guid,
136
493
         16,
137
493
         NULL ) != 1 )
138
6
    {
139
6
      goto on_error_libvshadow_store;
140
6
    }
141
487
    if( libvshadow_store_get_copy_set_identifier(
142
487
         store,
143
487
         guid,
144
487
         16,
145
487
         NULL ) != 1 )
146
0
    {
147
0
      goto on_error_libvshadow_store;
148
0
    }
149
487
    if( libvshadow_store_get_attribute_flags(
150
487
         store,
151
487
         &value_32bit,
152
487
         NULL ) != 1 )
153
0
    {
154
0
      goto on_error_libvshadow_store;
155
0
    }
156
487
    if( libvshadow_store_get_number_of_blocks(
157
487
         store,
158
487
         &number_of_blocks,
159
487
         NULL ) != 1 )
160
312
    {
161
312
      goto on_error_libvshadow_store;
162
312
    }
163
175
    if( libvshadow_store_get_size(
164
175
         store,
165
175
         &value_64bit,
166
175
         NULL ) != 1 )
167
0
    {
168
0
      goto on_error_libvshadow_store;
169
0
    }
170
175
    if( libvshadow_store_get_volume_size(
171
175
         store,
172
175
         &volume_size,
173
175
         NULL ) != 1 )
174
0
    {
175
0
      goto on_error_libvshadow_store;
176
0
    }
177
175
    for( read_iterator = 0;
178
5.69k
         read_iterator < 128;
179
5.52k
         read_iterator++ )
180
5.68k
    {
181
5.68k
      if( volume_offset >= volume_size )
182
26
      {
183
26
        break;
184
26
      }
185
5.66k
      if( libvshadow_store_read_buffer_at_offset(
186
5.66k
           store,
187
5.66k
           buffer,
188
5.66k
           497,
189
5.66k
           volume_offset,
190
5.66k
           NULL ) == -1 )
191
140
      {
192
140
        goto on_error_libvshadow_store;
193
140
      }
194
5.52k
      volume_offset += 497;
195
5.52k
    }
196
493
on_error_libvshadow_store:
197
493
    libvshadow_store_free(
198
493
     &store,
199
493
     NULL );
200
493
  }
201
559
  libvshadow_volume_close(
202
559
   volume,
203
559
   NULL );
204
205
2.43k
on_error_libvshadow_volume:
206
2.43k
  libvshadow_volume_free(
207
2.43k
   &volume,
208
2.43k
   NULL );
209
210
2.43k
on_error_libbfio:
211
2.43k
  libbfio_handle_free(
212
2.43k
   &file_io_handle,
213
2.43k
   NULL );
214
215
2.43k
  return( 0 );
216
2.43k
}
217
218
} /* extern "C" */
219