Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwsi/ossfuzz/item_list_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfwsi item list type
3
 *
4
 * Copyright (C) 2010-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
extern "C" {
26
27
#include "ossfuzz_libfwsi.h"
28
29
} /* extern "C" */
30
31
/* Retrieves a codepage based on the input
32
 * The input is mapped onto one of the supported codepages such that
33
 * the fuzz target exercises the codepage specific data conversion path.
34
 * The last entry is an unsupported codepage to exercise the validation path
35
 */
36
static int ossfuzz_libfwsi_get_codepage(
37
      const uint8_t *data,
38
      size_t size )
39
5.50k
{
40
5.50k
  static const int codepages[ 16 ] = {
41
5.50k
    LIBFWSI_CODEPAGE_US_ASCII,
42
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_874,
43
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_932,
44
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_936,
45
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_949,
46
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_950,
47
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1250,
48
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1251,
49
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1252,
50
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1253,
51
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1254,
52
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1255,
53
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1256,
54
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1257,
55
5.50k
    LIBFWSI_CODEPAGE_WINDOWS_1258,
56
5.50k
    LIBFWSI_CODEPAGE_ISO_LATIN_1
57
5.50k
  };
58
59
5.50k
  if( size == 0 )
60
0
  {
61
0
    return( LIBFWSI_CODEPAGE_US_ASCII );
62
0
  }
63
5.50k
  return( codepages[ data[ 0 ] % 16 ] );
64
5.50k
}
65
66
/* Retrieves the values of an item list
67
 */
68
static void ossfuzz_libfwsi_walk_item_list(
69
      libfwsi_item_list_t *item_list )
70
3.03k
{
71
3.03k
  libfwsi_item_t *item         = NULL;
72
3.03k
  size_t data_size             = 0;
73
3.03k
  int number_of_items          = 0;
74
3.03k
  int item_index               = 0;
75
76
3.03k
  libfwsi_item_list_get_data_size(
77
3.03k
   item_list,
78
3.03k
   &data_size,
79
3.03k
   NULL );
80
81
3.03k
  libfwsi_item_list_get_number_of_items(
82
3.03k
   item_list,
83
3.03k
   &number_of_items,
84
3.03k
   NULL );
85
86
3.03k
  for( item_index = 0;
87
201k
       item_index < number_of_items;
88
198k
       item_index++ )
89
198k
  {
90
198k
    if( libfwsi_item_list_get_item(
91
198k
         item_list,
92
198k
         item_index,
93
198k
         &item,
94
198k
         NULL ) == 1 )
95
198k
    {
96
198k
      item = NULL;
97
198k
    }
98
198k
  }
99
3.03k
}
100
101
extern "C" {
102
103
int LLVMFuzzerTestOneInput(
104
      const uint8_t *data,
105
      size_t size )
106
9.96k
{
107
9.96k
  libfwsi_item_list_t *item_list = NULL;
108
109
9.96k
  if( libfwsi_item_list_initialize(
110
9.96k
       &item_list,
111
9.96k
       NULL ) != 1 )
112
0
  {
113
0
    return( 0 );
114
0
  }
115
9.96k
  if( libfwsi_item_list_copy_from_byte_stream(
116
9.96k
       item_list,
117
9.96k
       data,
118
9.96k
       size,
119
9.96k
       ossfuzz_libfwsi_get_codepage(
120
9.96k
    data,
121
9.96k
    size ),
122
9.96k
       NULL ) == 1 )
123
6.59k
  {
124
6.59k
    ossfuzz_libfwsi_walk_item_list(
125
6.59k
     item_list );
126
6.59k
  }
127
9.96k
  libfwsi_item_list_free(
128
9.96k
   &item_list,
129
9.96k
   NULL );
130
131
9.96k
  return( 0 );
132
9.96k
}
133
134
} /* extern "C" */