Coverage Report

Created: 2026-05-30 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmsiecf/ossfuzz/item_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libmsiecf item type
3
 *
4
 * Copyright (C) 2009-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_libmsiecf.h"
31
32
#if !defined( LIBMSIECF_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
LIBMSIECF_EXTERN \
38
int libmsiecf_file_open_file_io_handle(
39
     libmsiecf_file_t *file,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libmsiecf_error_t **error );
43
44
#endif /* !defined( LIBMSIECF_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
10.1k
{
50
10.1k
  libbfio_handle_t *file_io_handle = NULL;
51
10.1k
  libmsiecf_file_t *file           = NULL;
52
10.1k
  libmsiecf_item_t *item           = NULL;
53
10.1k
  int number_of_items              = 0;
54
55
10.1k
  if( libbfio_memory_range_initialize(
56
10.1k
       &file_io_handle,
57
10.1k
       NULL ) != 1 )
58
0
  {
59
0
    return( 0 );
60
0
  }
61
10.1k
  if( libbfio_memory_range_set(
62
10.1k
       file_io_handle,
63
10.1k
       (uint8_t *) data,
64
10.1k
       size,
65
10.1k
       NULL ) != 1 )
66
0
  {
67
0
    goto on_error_libbfio;
68
0
  }
69
10.1k
  if( libmsiecf_file_initialize(
70
10.1k
       &file,
71
10.1k
       NULL ) != 1 )
72
0
  {
73
0
    goto on_error_libbfio;
74
0
  }
75
10.1k
  if( libmsiecf_file_open_file_io_handle(
76
10.1k
       file,
77
10.1k
       file_io_handle,
78
10.1k
       LIBMSIECF_OPEN_READ,
79
10.1k
       NULL ) != 1 )
80
4.82k
  {
81
4.82k
    goto on_error_libmsiecf_file;
82
4.82k
  }
83
5.34k
  if( libmsiecf_file_get_number_of_items(
84
5.34k
       file,
85
5.34k
       &number_of_items,
86
5.34k
       NULL ) != 1 )
87
0
  {
88
0
    goto on_error_libmsiecf_file;
89
0
  }
90
5.34k
  if( number_of_items > 0 )
91
3.13k
  {
92
3.13k
    if( libmsiecf_file_get_item_by_index(
93
3.13k
         file,
94
3.13k
         0,
95
3.13k
         &item,
96
3.13k
         NULL ) == 1 )
97
733
    {
98
733
      libmsiecf_item_free(
99
733
       &item,
100
733
       NULL );
101
733
    }
102
3.13k
  }
103
5.34k
  libmsiecf_file_close(
104
5.34k
   file,
105
5.34k
   NULL );
106
107
10.1k
on_error_libmsiecf_file:
108
10.1k
  libmsiecf_file_free(
109
10.1k
   &file,
110
10.1k
   NULL );
111
112
10.1k
on_error_libbfio:
113
10.1k
  libbfio_handle_free(
114
10.1k
   &file_io_handle,
115
10.1k
   NULL );
116
117
10.1k
  return( 0 );
118
10.1k
}
119
120
} /* extern "C" */
121