Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libolecf/ossfuzz/property_set_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libolecf property set type
3
 *
4
 * Copyright (C) 2008-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_libolecf.h"
31
32
#if !defined( LIBOLECF_HAVE_BFIO )
33
34
/* Opens a file using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBOLECF_EXTERN \
38
int libolecf_file_open_file_io_handle(
39
      libolecf_file_t *file,
40
      libbfio_handle_t *file_io_handle,
41
      int access_flags,
42
      libolecf_error_t **error );
43
44
#endif /* !defined( LIBOLECF_HAVE_BFIO ) */
45
46
/* Limits the number of sub items to walk to find a property set stream
47
 */
48
3.19k
#define FUZZER_SUB_ITEM_LIMIT 8
49
50
int LLVMFuzzerTestOneInput(
51
      const uint8_t *data,
52
      size_t size )
53
2.26k
{
54
2.26k
  uint8_t guid_data[ 16 ] = { 0 };
55
56
2.26k
  libbfio_handle_t *file_io_handle       = NULL;
57
2.26k
  libolecf_file_t *file                  = NULL;
58
2.26k
  libolecf_item_t *item                  = NULL;
59
2.26k
  libolecf_item_t *property_set_stream   = NULL;
60
2.26k
  libolecf_property_set_t *property_set      = NULL;
61
2.26k
  libolecf_property_section_t *property_section = NULL;
62
2.26k
  int number_of_sections   = 0;
63
2.26k
  int number_of_sub_items  = 0;
64
2.26k
  int result               = 0;
65
2.26k
  int sub_item_index       = 0;
66
67
2.26k
  if( libbfio_memory_range_initialize(
68
2.26k
       &file_io_handle,
69
2.26k
       NULL ) != 1 )
70
0
  {
71
0
    return( 0 );
72
0
  }
73
2.26k
  if( libbfio_memory_range_set(
74
2.26k
       file_io_handle,
75
2.26k
       (uint8_t *) data,
76
2.26k
       size,
77
2.26k
       NULL ) != 1 )
78
0
  {
79
0
    goto on_error_libbfio;
80
0
  }
81
2.26k
  if( libolecf_file_initialize(
82
2.26k
       &file,
83
2.26k
       NULL ) != 1 )
84
0
  {
85
0
    goto on_error_libbfio;
86
0
  }
87
2.26k
  if( libolecf_file_open_file_io_handle(
88
2.26k
       file,
89
2.26k
       file_io_handle,
90
2.26k
       LIBOLECF_OPEN_READ,
91
2.26k
       NULL ) != 1 )
92
939
  {
93
939
    goto on_error_libolecf_file;
94
939
  }
95
1.32k
  if( libolecf_file_get_root_item(
96
1.32k
       file,
97
1.32k
       &item,
98
1.32k
       NULL ) == 1 )
99
1.29k
  {
100
    /* Walk the sub items to find a property set stream
101
     */
102
1.29k
    if( libolecf_item_get_number_of_sub_items(
103
1.29k
         item,
104
1.29k
         &number_of_sub_items,
105
1.29k
         NULL ) == 1 )
106
1.29k
    {
107
1.29k
      for( sub_item_index = 0;
108
4.47k
           sub_item_index < number_of_sub_items;
109
3.18k
           sub_item_index++ )
110
3.19k
      {
111
3.19k
        property_set = NULL;
112
113
3.19k
        if( sub_item_index >= FUZZER_SUB_ITEM_LIMIT )
114
13
        {
115
13
          break;
116
13
        }
117
3.18k
        if( libolecf_item_get_sub_item(
118
3.18k
             item,
119
3.18k
             sub_item_index,
120
3.18k
             &property_set_stream,
121
3.18k
             NULL ) != 1 )
122
0
        {
123
0
          break;
124
0
        }
125
3.18k
        result = libolecf_property_set_stream_get_set(
126
3.18k
           property_set_stream,
127
3.18k
           &property_set,
128
3.18k
           NULL );
129
3.18k
        if( ( result != 1 )
130
13
         || ( property_set == NULL ) )
131
3.17k
        {
132
3.17k
          libolecf_item_free(
133
3.17k
           &property_set_stream,
134
3.17k
           NULL );
135
3.17k
          continue;
136
3.17k
        }
137
        /* Use the value as a sink to keep it live
138
         */
139
13
        guid_data[ 0 ] = 0;
140
13
        libolecf_property_set_get_class_identifier(
141
13
         property_set,
142
13
         guid_data,
143
13
         sizeof( guid_data ),
144
13
         NULL );
145
13
        if( libolecf_property_set_get_number_of_sections(
146
13
             property_set,
147
13
             &number_of_sections,
148
13
             NULL ) == 1 )
149
13
        {
150
13
          property_section = NULL;
151
13
          result = libolecf_property_set_get_section_by_index(
152
13
                   property_set,
153
13
                   0,
154
13
                   &property_section,
155
13
                   NULL );
156
13
          if( ( result == 1 )
157
7
           && ( property_section != NULL ) )
158
7
          {
159
7
            libolecf_property_section_free(
160
7
             &property_section,
161
7
             NULL );
162
7
          }
163
          /* Attempt to retrieve a property section
164
           * out of range to trigger the error handler
165
           */
166
13
          property_section = NULL;
167
13
          libolecf_property_set_get_section_by_index(
168
13
           property_set,
169
13
           number_of_sections,
170
13
           &property_section,
171
13
           NULL );
172
13
          if( property_section != NULL )
173
0
          {
174
0
            libolecf_property_section_free(
175
0
             &property_section,
176
0
             NULL );
177
0
          }
178
13
        }
179
13
        libolecf_property_set_free(
180
13
         &property_set,
181
13
         NULL );
182
13
        libolecf_item_free(
183
13
         &property_set_stream,
184
13
         NULL );
185
13
      }
186
1.29k
    }
187
1.29k
    libolecf_item_free(
188
1.29k
     &item,
189
1.29k
     NULL );
190
1.29k
  }
191
1.32k
  libolecf_file_close(
192
1.32k
   file,
193
1.32k
   NULL );
194
195
2.26k
on_error_libolecf_file:
196
2.26k
  libolecf_file_free(
197
2.26k
   &file,
198
2.26k
   NULL );
199
200
2.26k
on_error_libbfio:
201
2.26k
  libbfio_handle_free(
202
2.26k
   &file_io_handle,
203
2.26k
   NULL );
204
205
2.26k
  return( 0 );
206
2.26k
}
207
208
} /* extern "C" */