Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libolecf/ossfuzz/property_section_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libolecf property section 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
2.96k
#define FUZZER_SUB_ITEM_LIMIT 8
49
50
/* Limits the number of property sections to query
51
 */
52
202
#define FUZZER_SECTION_LIMIT  8
53
54
int LLVMFuzzerTestOneInput(
55
      const uint8_t *data,
56
      size_t size )
57
2.36k
{
58
2.36k
  uint8_t guid_data[ 16 ] = { 0 };
59
60
2.36k
  libbfio_handle_t *file_io_handle       = NULL;
61
2.36k
  libolecf_file_t *file                  = NULL;
62
2.36k
  libolecf_item_t *item                  = NULL;
63
2.36k
  libolecf_item_t *property_set_stream   = NULL;
64
2.36k
  libolecf_property_set_t *property_set      = NULL;
65
2.36k
  libolecf_property_section_t *property_section = NULL;
66
2.36k
  libolecf_property_value_t *property_value  = NULL;
67
2.36k
  int number_of_properties = 0;
68
2.36k
  int number_of_sections   = 0;
69
2.36k
  int number_of_sub_items  = 0;
70
2.36k
  int result               = 0;
71
2.36k
  int section_index        = 0;
72
2.36k
  int sub_item_index       = 0;
73
74
2.36k
  if( libbfio_memory_range_initialize(
75
2.36k
       &file_io_handle,
76
2.36k
       NULL ) != 1 )
77
0
  {
78
0
    return( 0 );
79
0
  }
80
2.36k
  if( libbfio_memory_range_set(
81
2.36k
       file_io_handle,
82
2.36k
       (uint8_t *) data,
83
2.36k
       size,
84
2.36k
       NULL ) != 1 )
85
0
  {
86
0
    goto on_error_libbfio;
87
0
  }
88
2.36k
  if( libolecf_file_initialize(
89
2.36k
       &file,
90
2.36k
       NULL ) != 1 )
91
0
  {
92
0
    goto on_error_libbfio;
93
0
  }
94
2.36k
  if( libolecf_file_open_file_io_handle(
95
2.36k
       file,
96
2.36k
       file_io_handle,
97
2.36k
       LIBOLECF_OPEN_READ,
98
2.36k
       NULL ) != 1 )
99
935
  {
100
935
    goto on_error_libolecf_file;
101
935
  }
102
1.42k
  if( libolecf_file_get_root_item(
103
1.42k
       file,
104
1.42k
       &item,
105
1.42k
       NULL ) == 1 )
106
1.38k
  {
107
    /* Walk the sub items to find a property set stream
108
     */
109
1.38k
    if( libolecf_item_get_number_of_sub_items(
110
1.38k
         item,
111
1.38k
         &number_of_sub_items,
112
1.38k
         NULL ) == 1 )
113
1.38k
    {
114
1.38k
      for( sub_item_index = 0;
115
4.33k
           sub_item_index < number_of_sub_items;
116
2.95k
           sub_item_index++ )
117
2.96k
      {
118
2.96k
        property_set = NULL;
119
120
2.96k
        if( sub_item_index >= FUZZER_SUB_ITEM_LIMIT )
121
9
        {
122
9
          break;
123
9
        }
124
2.95k
        if( libolecf_item_get_sub_item(
125
2.95k
             item,
126
2.95k
             sub_item_index,
127
2.95k
             &property_set_stream,
128
2.95k
             NULL ) != 1 )
129
0
        {
130
0
          break;
131
0
        }
132
2.95k
        result = libolecf_property_set_stream_get_set(
133
2.95k
           property_set_stream,
134
2.95k
           &property_set,
135
2.95k
           NULL );
136
2.95k
        if( ( result != 1 )
137
52
         || ( property_set == NULL ) )
138
2.89k
        {
139
2.89k
          libolecf_item_free(
140
2.89k
           &property_set_stream,
141
2.89k
           NULL );
142
2.89k
          continue;
143
2.89k
        }
144
52
        if( libolecf_property_set_get_number_of_sections(
145
52
             property_set,
146
52
             &number_of_sections,
147
52
             NULL ) == 1 )
148
52
        {
149
52
          for( section_index = 0;
150
244
               section_index < number_of_sections;
151
192
               section_index++ )
152
202
          {
153
202
            property_section     = NULL;
154
202
            number_of_properties = 0;
155
156
202
            if( section_index >= FUZZER_SECTION_LIMIT )
157
10
            {
158
10
              break;
159
10
            }
160
192
            result = libolecf_property_set_get_section_by_index(
161
192
               property_set,
162
192
               section_index,
163
192
               &property_section,
164
192
               NULL );
165
192
            if( ( result != 1 )
166
192
             || ( property_section == NULL ) )
167
0
            {
168
0
              continue;
169
0
            }
170
            /* Use the value as a sink to keep it live
171
             */
172
192
            guid_data[ 0 ] = 0;
173
192
            libolecf_property_section_get_class_identifier(
174
192
             property_section,
175
192
             guid_data,
176
192
             sizeof( guid_data ),
177
192
             NULL );
178
192
            if( libolecf_property_section_get_number_of_properties(
179
192
                 property_section,
180
192
                 &number_of_properties,
181
192
                 NULL ) == 1 )
182
192
            {
183
192
              property_value = NULL;
184
192
              result = libolecf_property_section_get_property_by_index(
185
192
                       property_section,
186
192
                       0,
187
192
                       &property_value,
188
192
                       NULL );
189
192
              if( ( result == 1 )
190
79
               && ( property_value != NULL ) )
191
79
              {
192
79
                libolecf_property_value_free(
193
79
                 &property_value,
194
79
                 NULL );
195
79
              }
196
              /* Attempt to retrieve a property value
197
               * out of range to trigger the error handler
198
               */
199
192
              property_value = NULL;
200
192
              libolecf_property_section_get_property_by_index(
201
192
               property_section,
202
192
               number_of_properties,
203
192
               &property_value,
204
192
               NULL );
205
192
              if( property_value != NULL )
206
0
              {
207
0
                libolecf_property_value_free(
208
0
                 &property_value,
209
0
                 NULL );
210
0
              }
211
192
            }
212
192
            libolecf_property_section_free(
213
192
             &property_section,
214
192
             NULL );
215
192
          }
216
          /* Attempt to retrieve a property section
217
           * out of range to trigger the error handler
218
           */
219
52
          property_section = NULL;
220
52
          libolecf_property_set_get_section_by_index(
221
52
           property_set,
222
52
           number_of_sections,
223
52
           &property_section,
224
52
           NULL );
225
52
          if( property_section != NULL )
226
0
          {
227
0
            libolecf_property_section_free(
228
0
             &property_section,
229
0
             NULL );
230
0
          }
231
52
        }
232
52
        libolecf_property_set_free(
233
52
         &property_set,
234
52
         NULL );
235
52
        libolecf_item_free(
236
52
         &property_set_stream,
237
52
         NULL );
238
52
      }
239
1.38k
    }
240
1.38k
    libolecf_item_free(
241
1.38k
     &item,
242
1.38k
     NULL );
243
1.38k
  }
244
1.42k
  libolecf_file_close(
245
1.42k
   file,
246
1.42k
   NULL );
247
248
2.36k
on_error_libolecf_file:
249
2.36k
  libolecf_file_free(
250
2.36k
   &file,
251
2.36k
   NULL );
252
253
2.36k
on_error_libbfio:
254
2.36k
  libbfio_handle_free(
255
2.36k
   &file_io_handle,
256
2.36k
   NULL );
257
258
2.36k
  return( 0 );
259
2.36k
}
260
261
} /* extern "C" */