Coverage Report

Created: 2026-07-25 07:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libesedb/ossfuzz/record_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libesedb record type
3
 *
4
 * Copyright (C) 2011-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_libesedb.h"
31
32
#if !defined( LIBESEDB_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
LIBESEDB_EXTERN \
38
int libesedb_file_open_file_io_handle(
39
     libesedb_file_t *file,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libesedb_error_t **error );
43
44
#endif /* !defined( LIBESEDB_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
3.79k
{
50
3.79k
  libbfio_handle_t *file_io_handle = NULL;
51
3.79k
  libesedb_file_t *file            = NULL;
52
3.79k
  libesedb_record_t *record        = NULL;
53
3.79k
  libesedb_table_t *table          = NULL;
54
3.79k
  int number_of_records            = 0;
55
3.79k
  int number_of_tables             = 0;
56
57
3.79k
  if( libbfio_memory_range_initialize(
58
3.79k
       &file_io_handle,
59
3.79k
       NULL ) != 1 )
60
0
  {
61
0
    return( 0 );
62
0
  }
63
3.79k
  if( libbfio_memory_range_set(
64
3.79k
       file_io_handle,
65
3.79k
       (uint8_t *) data,
66
3.79k
       size,
67
3.79k
       NULL ) != 1 )
68
0
  {
69
0
    goto on_error_libbfio;
70
0
  }
71
3.79k
  if( libesedb_file_initialize(
72
3.79k
       &file,
73
3.79k
       NULL ) != 1 )
74
0
  {
75
0
    goto on_error_libbfio;
76
0
  }
77
3.79k
  if( libesedb_file_open_file_io_handle(
78
3.79k
       file,
79
3.79k
       file_io_handle,
80
3.79k
       LIBESEDB_OPEN_READ,
81
3.79k
       NULL ) != 1 )
82
2.93k
  {
83
2.93k
    goto on_error_libesedb_file;
84
2.93k
  }
85
856
  if( libesedb_file_get_number_of_tables(
86
856
       file,
87
856
       &number_of_tables,
88
856
       NULL ) != 1 )
89
0
  {
90
0
    goto on_error_libesedb_file;
91
0
  }
92
856
  if( number_of_tables > 0 )
93
746
  {
94
746
    if( libesedb_file_get_table(
95
746
         file,
96
746
         0,
97
746
         &table,
98
746
         NULL ) == 1 )
99
474
    {
100
474
      if( libesedb_table_get_number_of_records(
101
474
           table,
102
474
           &number_of_records,
103
474
           NULL ) != 1 )
104
92
      {
105
92
        goto on_error_libesedb_table;
106
92
      }
107
382
      if( number_of_records > 0 )
108
373
      {
109
373
        if( libesedb_table_get_record(
110
373
             table,
111
373
             0,
112
373
             &record,
113
373
             NULL ) == 1 )
114
147
        {
115
147
          libesedb_record_free(
116
147
           &record,
117
147
           NULL );
118
147
        }
119
373
      }
120
474
on_error_libesedb_table:
121
474
      libesedb_table_free(
122
474
       &table,
123
474
       NULL );
124
474
    }
125
746
  }
126
856
  libesedb_file_close(
127
856
   file,
128
856
   NULL );
129
130
3.79k
on_error_libesedb_file:
131
3.79k
  libesedb_file_free(
132
3.79k
   &file,
133
3.79k
   NULL );
134
135
3.79k
on_error_libbfio:
136
3.79k
  libbfio_handle_free(
137
3.79k
   &file_io_handle,
138
3.79k
   NULL );
139
140
3.79k
  return( 0 );
141
3.79k
}
142
143
} /* extern "C" */
144