Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwps/ossfuzz/store_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfwps store 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.48k
{
38
  /* The supported codepages
39
   */
40
1.48k
  static const int ascii_codepages[] = {
41
1.48k
    LIBFWPS_CODEPAGE_WINDOWS_1252,
42
1.48k
    LIBFWPS_CODEPAGE_WINDOWS_1251,
43
1.48k
    LIBFWPS_CODEPAGE_WINDOWS_1250,
44
1.48k
    LIBFWPS_CODEPAGE_WINDOWS_936,
45
1.48k
    LIBFWPS_CODEPAGE_ISO_8859_1,
46
1.48k
    LIBFWPS_CODEPAGE_ISO_8859_5,
47
1.48k
    LIBFWPS_CODEPAGE_KOI8_R,
48
1.48k
    LIBFWPS_CODEPAGE_ASCII,
49
1.48k
    65000, /* UTF-7 */
50
1.48k
    65001  /* UTF-8 */ };
51
52
1.48k
  return( ascii_codepages[
53
1.48k
            byte_stream_size % ( sizeof( ascii_codepages ) / sizeof( ascii_codepages[ 0 ] ) ) ] );
54
1.48k
}
55
56
int LLVMFuzzerTestOneInput(
57
      const uint8_t *data,
58
      size_t size )
59
2.85k
{
60
2.85k
  libfwps_set_t *set                    = NULL;
61
2.85k
  libfwps_store_t *store                = NULL;
62
2.85k
  uint8_t guid_data[ 16 ]               = { 0 };
63
2.85k
  int number_of_sets                    = 0;
64
2.85k
  int set_index                         = 0;
65
66
2.85k
  if( libfwps_store_initialize(
67
2.85k
       &store,
68
2.85k
       NULL ) != 1 )
69
0
  {
70
0
    return( 0 );
71
0
  }
72
2.85k
  libfwps_store_copy_from_byte_stream(
73
2.85k
   store,
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_store_get_number_of_sets(
80
2.85k
       store,
81
2.85k
       &number_of_sets,
82
2.85k
       NULL ) == 1 )
83
2.85k
  {
84
2.85k
    for( set_index = 0;
85
682k
         set_index < number_of_sets;
86
679k
         set_index++ )
87
679k
    {
88
679k
      set = NULL;
89
90
679k
      if( libfwps_store_get_set_by_index(
91
679k
           store,
92
679k
           set_index,
93
679k
           &set,
94
679k
           NULL ) != 1
95
679k
       || set == NULL )
96
0
      {
97
0
        continue;
98
0
      }
99
679k
      libfwps_set_get_identifier(
100
679k
       set,
101
679k
       guid_data,
102
679k
       16,
103
679k
       NULL );
104
679k
      libfwps_format_class_identifier_get_identifier(
105
679k
       guid_data );
106
679k
      libfwps_format_class_identifier_get_description(
107
679k
       guid_data );
108
679k
    }
109
2.85k
  }
110
2.85k
  libfwps_store_free(
111
2.85k
   &store,
112
2.85k
   NULL );
113
114
2.85k
  return( 0 );
115
2.85k
}
116
117
} /* extern "C" */