Coverage Report

Created: 2025-06-24 07:14

/src/libfwps/ossfuzz/record_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libfwps set type
3
 *
4
 * Copyright (C) 2013-2024, 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_libfwps.h"
30
31
int LLVMFuzzerTestOneInput(
32
     const uint8_t *data,
33
     size_t size )
34
1.31k
{
35
1.31k
  libfwps_record_t *record = NULL;
36
1.31k
  libfwps_set_t *set       = NULL;
37
1.31k
  int number_of_records    = 0;
38
39
1.31k
  if( libfwps_set_initialize(
40
1.31k
       &set,
41
1.31k
       NULL ) != 1 )
42
0
  {
43
0
    return( 0 );
44
0
  }
45
1.31k
  libfwps_set_copy_from_byte_stream(
46
1.31k
   set,
47
1.31k
   data,
48
1.31k
   size,
49
1.31k
   LIBFWPS_CODEPAGE_WINDOWS_1252,
50
1.31k
   NULL );
51
52
1.31k
  if( libfwps_set_get_number_of_records(
53
1.31k
       set,
54
1.31k
       &number_of_records,
55
1.31k
       NULL ) != 1 )
56
0
  {
57
0
    goto on_error_libfwps_set;
58
0
  }
59
1.31k
  if( number_of_records > 0 )
60
575
  {
61
575
    if( libfwps_set_get_record_by_index(
62
575
         set,
63
575
         0,
64
575
         &record,
65
575
         NULL ) != 1 )
66
0
    {
67
0
      goto on_error_libfwps_set;
68
0
    }
69
575
    libfwps_record_free(
70
575
     &record,
71
575
     NULL );
72
575
  }
73
1.31k
on_error_libfwps_set:
74
1.31k
  libfwps_set_free(
75
1.31k
   &set,
76
1.31k
   NULL );
77
78
1.31k
  return( 0 );
79
1.31k
}
80
81
} /* extern "C" */
82