Coverage Report

Created: 2026-04-10 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libolecf/ossfuzz/item_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libolecf item type
3
 *
4
 * Copyright (C) 2008-2025, 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
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
25.1k
{
50
25.1k
  libbfio_handle_t *file_io_handle = NULL;
51
25.1k
  libolecf_file_t *file            = NULL;
52
25.1k
  libolecf_item_t *root_item       = NULL;
53
25.1k
  libolecf_item_t *sub_item        = NULL;
54
25.1k
  int number_of_sub_items          = 0;
55
56
25.1k
  if( libbfio_memory_range_initialize(
57
25.1k
       &file_io_handle,
58
25.1k
       NULL ) != 1 )
59
0
  {
60
0
    return( 0 );
61
0
  }
62
25.1k
  if( libbfio_memory_range_set(
63
25.1k
       file_io_handle,
64
25.1k
       (uint8_t *) data,
65
25.1k
       size,
66
25.1k
       NULL ) != 1 )
67
0
  {
68
0
    goto on_error_libbfio;
69
0
  }
70
25.1k
  if( libolecf_file_initialize(
71
25.1k
       &file,
72
25.1k
       NULL ) != 1 )
73
0
  {
74
0
    goto on_error_libbfio;
75
0
  }
76
25.1k
  if( libolecf_file_open_file_io_handle(
77
25.1k
       file,
78
25.1k
       file_io_handle,
79
25.1k
       LIBOLECF_OPEN_READ,
80
25.1k
       NULL ) != 1 )
81
13.4k
  {
82
13.4k
    goto on_error_libolecf_file;
83
13.4k
  }
84
11.7k
  if( libolecf_file_get_root_item(
85
11.7k
       file,
86
11.7k
       &root_item,
87
11.7k
       NULL ) == 1 )
88
3.18k
  {
89
3.18k
    if( libolecf_item_get_number_of_sub_items(
90
3.18k
         root_item,
91
3.18k
         &number_of_sub_items,
92
3.18k
         NULL ) != 1 )
93
1.96k
    {
94
1.96k
      goto on_error_libolecf_root_item;
95
1.96k
    }
96
1.22k
    if( number_of_sub_items > 0 )
97
773
    {
98
773
      if( libolecf_item_get_sub_item(
99
773
           root_item,
100
773
           0,
101
773
           &sub_item,
102
773
           NULL ) != 1 )
103
215
      {
104
215
        goto on_error_libolecf_root_item;
105
215
      }
106
558
      libolecf_item_free(
107
558
       &sub_item,
108
558
       NULL );
109
558
    }
110
3.18k
on_error_libolecf_root_item:
111
3.18k
    libolecf_item_free(
112
3.18k
     &root_item,
113
3.18k
     NULL );
114
3.18k
  }
115
11.7k
  libolecf_file_close(
116
11.7k
   file,
117
11.7k
   NULL );
118
119
25.1k
on_error_libolecf_file:
120
25.1k
  libolecf_file_free(
121
25.1k
   &file,
122
25.1k
   NULL );
123
124
25.1k
on_error_libbfio:
125
25.1k
  libbfio_handle_free(
126
25.1k
   &file_io_handle,
127
25.1k
   NULL );
128
129
25.1k
  return( 0 );
130
25.1k
}
131
132
} /* extern "C" */
133