Coverage Report

Created: 2026-08-31 07:43

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