Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libolecf/ossfuzz/property_value_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libolecf property value 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
#include <stdlib.h>
26
27
/* Note that some of the OSS-Fuzz engines use C++
28
 */
29
extern "C" {
30
31
#include "ossfuzz_libbfio.h"
32
#include "ossfuzz_libolecf.h"
33
34
#if !defined( LIBOLECF_HAVE_BFIO )
35
36
/* Opens a file using a Basic File IO (bfio) handle
37
 * Returns 1 if successful or -1 on error
38
 */
39
LIBOLECF_EXTERN \
40
int libolecf_file_open_file_io_handle(
41
      libolecf_file_t *file,
42
      libbfio_handle_t *file_io_handle,
43
      int access_flags,
44
      libolecf_error_t **error );
45
46
#endif /* !defined( LIBOLECF_HAVE_BFIO ) */
47
48
/* Limits the size of the value and string buffers
49
 */
50
5.67k
#define FUZZER_DATA_SIZE_LIMIT  ( (size_t) 0x10000 )
51
52
/* Limits the number of sub items to walk to find a property set stream
53
 */
54
3.94k
#define FUZZER_SUB_ITEM_LIMIT 8
55
56
/* Limits the number of property sections to query
57
 */
58
744
#define FUZZER_SECTION_LIMIT  8
59
60
/* Limits the number of property values to query
61
 */
62
3.62k
#define FUZZER_PROPERTY_LIMIT 16
63
64
int LLVMFuzzerTestOneInput(
65
      const uint8_t *data,
66
      size_t size )
67
2.44k
{
68
2.44k
  uint8_t *value_data    = NULL;
69
2.44k
  uint8_t *utf8_string   = NULL;
70
2.44k
  uint16_t *utf16_string = NULL;
71
72
2.44k
  libbfio_handle_t *file_io_handle      = NULL;
73
2.44k
  libolecf_file_t *file                 = NULL;
74
2.44k
  libolecf_item_t *item                 = NULL;
75
2.44k
  libolecf_item_t *property_set_stream  = NULL;
76
2.44k
  libolecf_property_set_t *property_set      = NULL;
77
2.44k
  libolecf_property_section_t *property_section = NULL;
78
2.44k
  libolecf_property_value_t *property_value   = NULL;
79
2.44k
  uint8_t value_boolean      = 0;
80
2.44k
  uint16_t value_16bit       = 0;
81
2.44k
  uint32_t identifier        = 0;
82
2.44k
  uint32_t value_32bit       = 0;
83
2.44k
  uint32_t value_type        = 0;
84
2.44k
  uint64_t value_64bit       = 0;
85
2.44k
  uint64_t value_filetime    = 0;
86
2.44k
  size_t value_data_size     = 0;
87
2.44k
  size_t utf8_string_size    = 0;
88
2.44k
  size_t utf16_string_size   = 0;
89
2.44k
  int number_of_properties   = 0;
90
2.44k
  int number_of_sections     = 0;
91
2.44k
  int number_of_sub_items    = 0;
92
2.44k
  int property_index         = 0;
93
2.44k
  int result                 = 0;
94
2.44k
  int section_index          = 0;
95
2.44k
  int sub_item_index         = 0;
96
97
2.44k
  if( libbfio_memory_range_initialize(
98
2.44k
       &file_io_handle,
99
2.44k
       NULL ) != 1 )
100
0
  {
101
0
    return( 0 );
102
0
  }
103
2.44k
  if( libbfio_memory_range_set(
104
2.44k
       file_io_handle,
105
2.44k
       (uint8_t *) data,
106
2.44k
       size,
107
2.44k
       NULL ) != 1 )
108
0
  {
109
0
    goto on_error_libbfio;
110
0
  }
111
2.44k
  if( libolecf_file_initialize(
112
2.44k
       &file,
113
2.44k
       NULL ) != 1 )
114
0
  {
115
0
    goto on_error_libbfio;
116
0
  }
117
2.44k
  if( libolecf_file_open_file_io_handle(
118
2.44k
       file,
119
2.44k
       file_io_handle,
120
2.44k
       LIBOLECF_OPEN_READ,
121
2.44k
       NULL ) != 1 )
122
1.00k
  {
123
1.00k
    goto on_error_libolecf_file;
124
1.00k
  }
125
1.43k
  if( libolecf_file_get_root_item(
126
1.43k
       file,
127
1.43k
       &item,
128
1.43k
       NULL ) == 1 )
129
1.39k
  {
130
    /* Walk the sub items to find a property set stream
131
     */
132
1.39k
    if( libolecf_item_get_number_of_sub_items(
133
1.39k
         item,
134
1.39k
         &number_of_sub_items,
135
1.39k
         NULL ) == 1 )
136
1.39k
    {
137
1.39k
      for( sub_item_index = 0;
138
5.31k
           sub_item_index < number_of_sub_items;
139
3.92k
           sub_item_index++ )
140
3.94k
      {
141
3.94k
        property_set = NULL;
142
143
3.94k
        if( sub_item_index >= FUZZER_SUB_ITEM_LIMIT )
144
23
        {
145
23
          break;
146
23
        }
147
3.92k
        if( libolecf_item_get_sub_item(
148
3.92k
             item,
149
3.92k
             sub_item_index,
150
3.92k
             &property_set_stream,
151
3.92k
             NULL ) != 1 )
152
0
        {
153
0
          break;
154
0
        }
155
3.92k
        result = libolecf_property_set_stream_get_set(
156
3.92k
           property_set_stream,
157
3.92k
           &property_set,
158
3.92k
           NULL );
159
3.92k
        if( ( result != 1 )
160
629
         || ( property_set == NULL ) )
161
3.29k
        {
162
3.29k
          libolecf_item_free(
163
3.29k
           &property_set_stream,
164
3.29k
           NULL );
165
3.29k
          continue;
166
3.29k
        }
167
629
        if( libolecf_property_set_get_number_of_sections(
168
629
             property_set,
169
629
             &number_of_sections,
170
629
             NULL ) == 1 )
171
629
        {
172
629
          for( section_index = 0;
173
1.36k
               section_index < number_of_sections;
174
736
               section_index++ )
175
744
          {
176
744
            property_section     = NULL;
177
744
            number_of_properties = 0;
178
179
744
            if( section_index >= FUZZER_SECTION_LIMIT )
180
8
            {
181
8
              break;
182
8
            }
183
736
            result = libolecf_property_set_get_section_by_index(
184
736
               property_set,
185
736
               section_index,
186
736
               &property_section,
187
736
               NULL );
188
736
            if( ( result != 1 )
189
736
             || ( property_section == NULL ) )
190
0
            {
191
0
              continue;
192
0
            }
193
736
            if( libolecf_property_section_get_number_of_properties(
194
736
                 property_section,
195
736
                 &number_of_properties,
196
736
                 NULL ) == 1 )
197
736
            {
198
736
              for( property_index = 0;
199
4.33k
                   property_index < number_of_properties;
200
3.59k
                   property_index++ )
201
3.62k
              {
202
3.62k
                property_value = NULL;
203
204
3.62k
                if( property_index >= FUZZER_PROPERTY_LIMIT )
205
27
                {
206
27
                  break;
207
27
                }
208
3.59k
                result = libolecf_property_section_get_property_by_index(
209
3.59k
                   property_section,
210
3.59k
                   property_index,
211
3.59k
                   &property_value,
212
3.59k
                   NULL );
213
3.59k
                if( ( result != 1 )
214
3.59k
                 || ( property_value == NULL ) )
215
0
                {
216
0
                  continue;
217
0
                }
218
3.59k
                libolecf_property_value_get_identifier(
219
3.59k
                 property_value,
220
3.59k
                 &identifier,
221
3.59k
                 NULL );
222
3.59k
                libolecf_property_value_get_value_type(
223
3.59k
                 property_value,
224
3.59k
                 &value_type,
225
3.59k
                 NULL );
226
3.59k
                result = libolecf_property_value_get_data_size(
227
3.59k
                   property_value,
228
3.59k
                   &value_data_size,
229
3.59k
                   NULL );
230
3.59k
                if( ( result == 1 )
231
2.06k
                 && ( value_data_size > 0 ) )
232
1.86k
                {
233
1.86k
                  if( value_data_size > FUZZER_DATA_SIZE_LIMIT )
234
0
                  {
235
0
                    value_data_size = FUZZER_DATA_SIZE_LIMIT;
236
0
                  }
237
1.86k
                  value_data = (uint8_t *) malloc( value_data_size );
238
239
1.86k
                  if( value_data != NULL )
240
1.86k
                  {
241
1.86k
                    if( libolecf_property_value_get_data(
242
1.86k
                         property_value,
243
1.86k
                         value_data,
244
1.86k
                         value_data_size,
245
1.86k
                         NULL ) == 1 )
246
1.86k
                    {
247
                      /* Use the value as a sink
248
                       * to keep it live
249
                       */
250
1.86k
                      value_boolean = value_data[ 0 ];
251
1.86k
                    }
252
1.86k
                    free( value_data );
253
1.86k
                    value_data = NULL;
254
1.86k
                  }
255
1.86k
                }
256
3.59k
                libolecf_property_value_get_data_as_boolean(
257
3.59k
                 property_value,
258
3.59k
                 &value_boolean,
259
3.59k
                 NULL );
260
3.59k
                libolecf_property_value_get_data_as_16bit_integer(
261
3.59k
                 property_value,
262
3.59k
                 &value_16bit,
263
3.59k
                 NULL );
264
3.59k
                libolecf_property_value_get_data_as_32bit_integer(
265
3.59k
                 property_value,
266
3.59k
                 &value_32bit,
267
3.59k
                 NULL );
268
3.59k
                libolecf_property_value_get_data_as_64bit_integer(
269
3.59k
                 property_value,
270
3.59k
                 &value_64bit,
271
3.59k
                 NULL );
272
3.59k
                libolecf_property_value_get_data_as_filetime(
273
3.59k
                 property_value,
274
3.59k
                 &value_filetime,
275
3.59k
                 NULL );
276
3.59k
                result = libolecf_property_value_get_data_as_utf8_string_size(
277
3.59k
                   property_value,
278
3.59k
                   &utf8_string_size,
279
3.59k
                   NULL );
280
3.59k
                if( ( result == 1 )
281
529
                 && ( utf8_string_size > 0 ) )
282
487
                {
283
487
                  if( utf8_string_size > FUZZER_DATA_SIZE_LIMIT )
284
0
                  {
285
0
                    utf8_string_size = FUZZER_DATA_SIZE_LIMIT;
286
0
                  }
287
487
                  utf8_string = (uint8_t *) malloc( utf8_string_size );
288
289
487
                  if( utf8_string != NULL )
290
487
                  {
291
487
                    if( libolecf_property_value_get_data_as_utf8_string(
292
487
                         property_value,
293
487
                         utf8_string,
294
487
                         utf8_string_size,
295
487
                         NULL ) == 1 )
296
487
                    {
297
487
                      utf8_string[ utf8_string_size - 1 ] = 0;
298
299
                      /* Use the value as a sink
300
                       * to keep it live
301
                       */
302
487
                      value_boolean = utf8_string[ 0 ];
303
487
                    }
304
487
                    free( utf8_string );
305
487
                    utf8_string = NULL;
306
487
                  }
307
487
                }
308
3.59k
                result = libolecf_property_value_get_data_as_utf16_string_size(
309
3.59k
                   property_value,
310
3.59k
                   &utf16_string_size,
311
3.59k
                   NULL );
312
3.59k
                if( ( result == 1 )
313
529
                 && ( utf16_string_size > 0 ) )
314
487
                {
315
487
                  if( utf16_string_size > FUZZER_DATA_SIZE_LIMIT )
316
0
                  {
317
0
                    utf16_string_size = FUZZER_DATA_SIZE_LIMIT;
318
0
                  }
319
                  /* The size is the number of UTF-16
320
                   * characters, including the end of
321
                   * string character
322
                   */
323
487
                  utf16_string = (uint16_t *) malloc( utf16_string_size * sizeof( uint16_t ) );
324
325
487
                  if( utf16_string != NULL )
326
487
                  {
327
487
                    if( libolecf_property_value_get_data_as_utf16_string(
328
487
                         property_value,
329
487
                         utf16_string,
330
487
                         utf16_string_size,
331
487
                         NULL ) == 1 )
332
487
                    {
333
487
                      utf16_string[ utf16_string_size - 1 ] = 0;
334
335
                      /* Use the value as a sink
336
                       * to keep it live
337
                       */
338
487
                      value_boolean = (uint8_t) utf16_string[ 0 ];
339
487
                    }
340
487
                    free( utf16_string );
341
487
                    utf16_string = NULL;
342
487
                  }
343
487
                }
344
                /* The deprecated accessors
345
                 */
346
3.59k
                result = libolecf_property_value_get_value_data_size(
347
3.59k
                   property_value,
348
3.59k
                   &value_data_size,
349
3.59k
                   NULL );
350
3.59k
                if( ( result == 1 )
351
2.06k
                 && ( value_data_size > 0 ) )
352
1.86k
                {
353
1.86k
                  if( value_data_size > FUZZER_DATA_SIZE_LIMIT )
354
0
                  {
355
0
                    value_data_size = FUZZER_DATA_SIZE_LIMIT;
356
0
                  }
357
1.86k
                  value_data = (uint8_t *) malloc( value_data_size );
358
359
1.86k
                  if( value_data != NULL )
360
1.86k
                  {
361
1.86k
                    if( libolecf_property_value_get_value_data(
362
1.86k
                         property_value,
363
1.86k
                         value_data,
364
1.86k
                         value_data_size,
365
1.86k
                         NULL ) == 1 )
366
1.86k
                    {
367
                      /* Use the value as a sink
368
                       * to keep it live
369
                       */
370
1.86k
                      value_boolean = value_data[ 0 ];
371
1.86k
                    }
372
1.86k
                    free( value_data );
373
1.86k
                    value_data = NULL;
374
1.86k
                  }
375
1.86k
                }
376
3.59k
                libolecf_property_value_get_value_boolean(
377
3.59k
                 property_value,
378
3.59k
                 &value_boolean,
379
3.59k
                 NULL );
380
3.59k
                libolecf_property_value_get_value_16bit(
381
3.59k
                 property_value,
382
3.59k
                 &value_16bit,
383
3.59k
                 NULL );
384
3.59k
                libolecf_property_value_get_value_32bit(
385
3.59k
                 property_value,
386
3.59k
                 &value_32bit,
387
3.59k
                 NULL );
388
3.59k
                libolecf_property_value_get_value_64bit(
389
3.59k
                 property_value,
390
3.59k
                 &value_64bit,
391
3.59k
                 NULL );
392
3.59k
                libolecf_property_value_get_value_filetime(
393
3.59k
                 property_value,
394
3.59k
                 &value_filetime,
395
3.59k
                 NULL );
396
3.59k
                result = libolecf_property_value_get_value_utf8_string_size(
397
3.59k
                   property_value,
398
3.59k
                   &utf8_string_size,
399
3.59k
                   NULL );
400
3.59k
                if( ( result == 1 )
401
529
                 && ( utf8_string_size > 0 ) )
402
487
                {
403
487
                  if( utf8_string_size > FUZZER_DATA_SIZE_LIMIT )
404
0
                  {
405
0
                    utf8_string_size = FUZZER_DATA_SIZE_LIMIT;
406
0
                  }
407
487
                  utf8_string = (uint8_t *) malloc( utf8_string_size );
408
409
487
                  if( utf8_string != NULL )
410
487
                  {
411
487
                    if( libolecf_property_value_get_value_utf8_string(
412
487
                         property_value,
413
487
                         utf8_string,
414
487
                         utf8_string_size,
415
487
                         NULL ) == 1 )
416
487
                    {
417
487
                      utf8_string[ utf8_string_size - 1 ] = 0;
418
419
                      /* Use the value as a sink
420
                       * to keep it live
421
                       */
422
487
                      value_boolean = utf8_string[ 0 ];
423
487
                    }
424
487
                    free( utf8_string );
425
487
                    utf8_string = NULL;
426
487
                  }
427
487
                }
428
3.59k
                result = libolecf_property_value_get_value_utf16_string_size(
429
3.59k
                   property_value,
430
3.59k
                   &utf16_string_size,
431
3.59k
                   NULL );
432
3.59k
                if( ( result == 1 )
433
529
                 && ( utf16_string_size > 0 ) )
434
487
                {
435
487
                  if( utf16_string_size > FUZZER_DATA_SIZE_LIMIT )
436
0
                  {
437
0
                    utf16_string_size = FUZZER_DATA_SIZE_LIMIT;
438
0
                  }
439
                  /* The size is the number of UTF-16
440
                   * characters, including the end of
441
                   * string character
442
                   */
443
487
                  utf16_string = (uint16_t *) malloc( utf16_string_size * sizeof( uint16_t ) );
444
445
487
                  if( utf16_string != NULL )
446
487
                  {
447
487
                    if( libolecf_property_value_get_value_utf16_string(
448
487
                         property_value,
449
487
                         utf16_string,
450
487
                         utf16_string_size,
451
487
                         NULL ) == 1 )
452
487
                    {
453
487
                      utf16_string[ utf16_string_size - 1 ] = 0;
454
455
                      /* Use the value as a sink
456
                       * to keep it live
457
                       */
458
487
                      value_boolean = (uint8_t) utf16_string[ 0 ];
459
487
                    }
460
487
                    free( utf16_string );
461
487
                    utf16_string = NULL;
462
487
                  }
463
487
                }
464
3.59k
                libolecf_property_value_free(
465
3.59k
                 &property_value,
466
3.59k
                 NULL );
467
3.59k
              }
468
736
            }
469
736
            libolecf_property_section_free(
470
736
             &property_section,
471
736
             NULL );
472
736
          }
473
629
        }
474
629
        libolecf_property_set_free(
475
629
         &property_set,
476
629
         NULL );
477
629
        libolecf_item_free(
478
629
         &property_set_stream,
479
629
         NULL );
480
629
      }
481
1.39k
    }
482
1.39k
    libolecf_item_free(
483
1.39k
     &item,
484
1.39k
     NULL );
485
1.39k
  }
486
1.43k
  libolecf_file_close(
487
1.43k
   file,
488
1.43k
   NULL );
489
490
2.44k
on_error_libolecf_file:
491
2.44k
  libolecf_file_free(
492
2.44k
   &file,
493
2.44k
   NULL );
494
495
2.44k
on_error_libbfio:
496
2.44k
  libbfio_handle_free(
497
2.44k
   &file_io_handle,
498
2.44k
   NULL );
499
500
2.44k
  return( 0 );
501
2.44k
}
502
503
} /* extern "C" */