Coverage Report

Created: 2026-07-25 07:30

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