Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwps/ossfuzz/set_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfwps set type
3
 *
4
 * Copyright (C) 2013-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_libfwps.h"
30
31
/* Retrieves an ASCII codepage based on the size of the byte stream
32
 * This varies the codepage used to convert ASCII formatted value data
33
 * including UTF-7 (65000) and UTF-8 (65001)
34
 */
35
static int ossfuzz_get_ascii_codepage(
36
      size_t byte_stream_size )
37
1.36k
{
38
  /* The supported codepages
39
   */
40
1.36k
  static const int ascii_codepages[] = {
41
1.36k
    LIBFWPS_CODEPAGE_WINDOWS_1252,
42
1.36k
    LIBFWPS_CODEPAGE_WINDOWS_1251,
43
1.36k
    LIBFWPS_CODEPAGE_WINDOWS_1250,
44
1.36k
    LIBFWPS_CODEPAGE_WINDOWS_936,
45
1.36k
    LIBFWPS_CODEPAGE_ISO_8859_1,
46
1.36k
    LIBFWPS_CODEPAGE_ISO_8859_5,
47
1.36k
    LIBFWPS_CODEPAGE_KOI8_R,
48
1.36k
    LIBFWPS_CODEPAGE_ASCII,
49
1.36k
    65000, /* UTF-7 */
50
1.36k
    65001  /* UTF-8 */ };
51
52
1.36k
  return( ascii_codepages[
53
1.36k
            byte_stream_size % ( sizeof( ascii_codepages ) / sizeof( ascii_codepages[ 0 ] ) ) ] );
54
1.36k
}
55
56
int LLVMFuzzerTestOneInput(
57
      const uint8_t *data,
58
      size_t size )
59
2.85k
{
60
2.85k
  libfwps_record_t *record              = NULL;
61
2.85k
  libfwps_set_t *set                    = NULL;
62
2.85k
  uint8_t guid_data[ 16 ]               = { 0 };
63
2.85k
  int number_of_records                 = 0;
64
2.85k
  int record_index                      = 0;
65
66
2.85k
  if( libfwps_set_initialize(
67
2.85k
       &set,
68
2.85k
       NULL ) != 1 )
69
0
  {
70
0
    return( 0 );
71
0
  }
72
2.85k
  libfwps_set_copy_from_byte_stream(
73
2.85k
   set,
74
2.85k
   data,
75
2.85k
   size,
76
2.85k
   ossfuzz_get_ascii_codepage( size ),
77
2.85k
   NULL );
78
79
2.85k
  if( libfwps_set_get_number_of_records(
80
2.85k
       set,
81
2.85k
       &number_of_records,
82
2.85k
       NULL ) == 1 )
83
2.85k
  {
84
2.85k
    for( record_index = 0;
85
682k
         record_index < number_of_records;
86
679k
         record_index++ )
87
679k
    {
88
679k
      record = NULL;
89
90
679k
      if( libfwps_set_get_record_by_index(
91
679k
           set,
92
679k
           record_index,
93
679k
           &record,
94
679k
           NULL ) != 1
95
679k
       || record == NULL )
96
0
      {
97
0
        continue;
98
0
      }
99
679k
      libfwps_record_free(
100
679k
       &record,
101
679k
       NULL );
102
679k
    }
103
2.85k
  }
104
2.85k
  libfwps_set_get_identifier(
105
2.85k
   set,
106
2.85k
   guid_data,
107
2.85k
   16,
108
2.85k
   NULL );
109
2.85k
  libfwps_format_class_identifier_get_identifier(
110
2.85k
   guid_data );
111
2.85k
  libfwps_format_class_identifier_get_description(
112
2.85k
   guid_data );
113
114
2.85k
  libfwps_set_free(
115
2.85k
   &set,
116
2.85k
   NULL );
117
118
2.85k
  return( 0 );
119
2.85k
}
120
121
} /* extern "C" */