Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvsgpt/ossfuzz/volume_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libvsgpt volume type
3
 *
4
 * Copyright (C) 2019-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_libvsgpt.h"
31
32
#if !defined( LIBVSGPT_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
LIBVSGPT_EXTERN \
38
int libvsgpt_volume_open_file_io_handle(
39
     libvsgpt_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libvsgpt_error_t **error );
43
44
#endif /* !defined( LIBVSGPT_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
1.59k
{
50
1.59k
  uint8_t guid[ 16 ];
51
52
1.59k
  libbfio_handle_t *file_io_handle = NULL;
53
1.59k
  libvsgpt_volume_t *volume        = NULL;
54
1.59k
  uint32_t value_32bit             = 0;
55
1.59k
  int number_of_partitions         = 0;
56
57
1.59k
  if( libbfio_memory_range_initialize(
58
1.59k
       &file_io_handle,
59
1.59k
       NULL ) != 1 )
60
0
  {
61
0
    return( 0 );
62
0
  }
63
1.59k
  if( libbfio_memory_range_set(
64
1.59k
       file_io_handle,
65
1.59k
       (uint8_t *) data,
66
1.59k
       size,
67
1.59k
       NULL ) != 1 )
68
0
  {
69
0
    goto on_error_libbfio;
70
0
  }
71
1.59k
  if( libvsgpt_volume_initialize(
72
1.59k
       &volume,
73
1.59k
       NULL ) != 1 )
74
0
  {
75
0
    goto on_error_libbfio;
76
0
  }
77
1.59k
  if( libvsgpt_volume_open_file_io_handle(
78
1.59k
       volume,
79
1.59k
       file_io_handle,
80
1.59k
       LIBVSGPT_OPEN_READ,
81
1.59k
       NULL ) != 1 )
82
1.49k
  {
83
1.49k
    goto on_error_libvsgpt;
84
1.49k
  }
85
99
  if( libvsgpt_volume_get_bytes_per_sector(
86
99
       volume,
87
99
       &value_32bit,
88
99
       NULL ) != 1 )
89
0
  {
90
0
    goto on_error_libvsgpt;
91
0
  }
92
99
  if( libvsgpt_volume_get_disk_identifier(
93
99
       volume,
94
99
       guid,
95
99
       16,
96
99
       NULL ) != 1 )
97
0
  {
98
0
    goto on_error_libvsgpt;
99
0
  }
100
99
  if( libvsgpt_volume_get_number_of_partitions(
101
99
       volume,
102
99
       &number_of_partitions,
103
99
       NULL ) != 1 )
104
0
  {
105
0
    goto on_error_libvsgpt;
106
0
  }
107
99
  libvsgpt_volume_close(
108
99
   volume,
109
99
   NULL );
110
111
1.59k
on_error_libvsgpt:
112
1.59k
  libvsgpt_volume_free(
113
1.59k
   &volume,
114
1.59k
   NULL );
115
116
1.59k
on_error_libbfio:
117
1.59k
  libbfio_handle_free(
118
1.59k
   &file_io_handle,
119
1.59k
   NULL );
120
121
1.59k
  return( 0 );
122
1.59k
}
123
124
} /* extern "C" */
125