Coverage Report

Created: 2025-09-27 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boost_ptree_xmlread_fuzzer.cc
Line
Count
Source
1
/*
2
 * Fuzzing of boost property tree parsers.
3
 * by Paul Dreik 20180818
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <boost/property_tree/xml_parser.hpp>
19
#include <sstream>
20
21
int
22
readXml(const char* Data, size_t Size)
23
8.91k
{
24
25
8.91k
  namespace pt = boost::property_tree;
26
27
8.91k
  if (Size < 1) {
28
    // no data to use for flags - skip.
29
0
    return 0;
30
0
  }
31
32
8.91k
  std::stringstream ss;
33
8.91k
  const auto firstbyte = Data[0];
34
35
8.91k
  ss.write(Data + 1, Size - 1);
36
37
8.91k
  pt::ptree tree;
38
39
8.91k
  try {
40
    // set the parse flags based on the first byte
41
8.91k
    int flags = 0;
42
8.91k
    if (firstbyte & 0x1) {
43
4.40k
      flags |= pt::xml_parser::no_concat_text;
44
4.40k
    }
45
8.91k
    if (firstbyte & 0x2) {
46
4.34k
      flags |= pt::xml_parser::no_comments;
47
4.34k
    }
48
8.91k
    if (firstbyte & 0x4) {
49
4.70k
      flags |= pt::xml_parser::trim_whitespace;
50
4.70k
    }
51
8.91k
    pt::read_xml(ss, tree, flags);
52
53
8.91k
    return tree.size() ? 1 : 0;
54
8.91k
  } catch (...) {
55
7.76k
    return 0;
56
7.76k
  }
57
8.91k
}
58
59
extern "C" int
60
LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
61
13.7k
{
62
13.7k
  readXml(reinterpret_cast<const char*>(Data), Size);
63
13.7k
  return 0;
64
13.7k
}