Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvsbsdl/ossfuzz/volume_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libvsbsdl volume type
3
 *
4
 * Copyright (C) 2023-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_libvsbsdl.h"
31
32
#if !defined( LIBVSBSDL_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
LIBVSBSDL_EXTERN \
38
int libvsbsdl_volume_open_file_io_handle(
39
     libvsbsdl_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libvsbsdl_error_t **error );
43
44
#endif /* !defined( LIBVSBSDL_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
481
{
50
481
  libbfio_handle_t *file_io_handle = NULL;
51
481
  libvsbsdl_volume_t *volume       = NULL;
52
481
  uint32_t value_32bit             = 0;
53
481
  int number_of_partitions         = 0;
54
55
481
  if( libbfio_memory_range_initialize(
56
481
       &file_io_handle,
57
481
       NULL ) != 1 )
58
0
  {
59
0
    return( 0 );
60
0
  }
61
481
  if( libbfio_memory_range_set(
62
481
       file_io_handle,
63
481
       (uint8_t *) data,
64
481
       size,
65
481
       NULL ) != 1 )
66
0
  {
67
0
    goto on_error_libbfio;
68
0
  }
69
481
  if( libvsbsdl_volume_initialize(
70
481
       &volume,
71
481
       NULL ) != 1 )
72
0
  {
73
0
    goto on_error_libbfio;
74
0
  }
75
481
  if( libvsbsdl_volume_open_file_io_handle(
76
481
       volume,
77
481
       file_io_handle,
78
481
       LIBVSBSDL_OPEN_READ,
79
481
       NULL ) != 1 )
80
447
  {
81
447
    goto on_error_libvsbsdl;
82
447
  }
83
34
  if( libvsbsdl_volume_get_bytes_per_sector(
84
34
       volume,
85
34
       &value_32bit,
86
34
       NULL ) != 1 )
87
0
  {
88
0
    goto on_error_libvsbsdl;
89
0
  }
90
34
  if( libvsbsdl_volume_get_number_of_partitions(
91
34
       volume,
92
34
       &number_of_partitions,
93
34
       NULL ) != 1 )
94
0
  {
95
0
    goto on_error_libvsbsdl;
96
0
  }
97
34
  libvsbsdl_volume_close(
98
34
   volume,
99
34
   NULL );
100
101
481
on_error_libvsbsdl:
102
481
  libvsbsdl_volume_free(
103
481
   &volume,
104
481
   NULL );
105
106
481
on_error_libbfio:
107
481
  libbfio_handle_free(
108
481
   &file_io_handle,
109
481
   NULL );
110
111
481
  return( 0 );
112
481
}
113
114
} /* extern "C" */
115