Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/librevenge/src/fuzz/commonfuzzer.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* librevenge
3
 * Version: MPL 2.0 / LGPLv2.1+
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * Alternatively, the contents of this file may be used under the terms
10
 * of the GNU Lesser General Public License Version 2.1 or later
11
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
12
 * applicable instead of those above.
13
 */
14
15
#include "commonfuzzer.h"
16
17
#include <algorithm>
18
#include <iterator>
19
#include <memory>
20
#include <vector>
21
22
namespace fuzz
23
{
24
25
namespace
26
{
27
28
unsigned long getLength(librevenge::RVNGInputStream &input)
29
77.5k
{
30
77.5k
  const long pos = input.tell();
31
77.5k
  if (0 > pos)
32
0
    return 0;
33
34
77.5k
  long end = 0;
35
36
77.5k
  if (0 == input.seek(0, librevenge::RVNG_SEEK_END))
37
77.5k
    end = input.tell();
38
77.5k
  if ((0 != input.seek(pos, librevenge::RVNG_SEEK_SET)) || (0 > end))
39
0
    return 0;
40
41
77.5k
  return static_cast<unsigned long>(end);
42
77.5k
}
43
44
void testRead(librevenge::RVNGInputStream &input, std::vector<unsigned char> &buf)
45
77.5k
{
46
77.5k
  const unsigned long size = getLength(input);
47
77.5k
  unsigned long readBytes = 0;
48
77.5k
  const unsigned char *data = input.read(size, readBytes);
49
77.5k
  buf.resize(size_t(size));
50
77.5k
  std::copy_n(data, size, std::back_inserter(buf));
51
77.5k
}
52
53
}
54
55
void testStructuredStream(librevenge::RVNGInputStream &input)
56
4.37k
{
57
4.37k
  std::vector<unsigned char> buf;
58
59
185k
  for (unsigned i = 0, ssc = input.subStreamCount(); i < ssc; ++i)
60
181k
  {
61
181k
    std::unique_ptr<librevenge::RVNGInputStream> subStream(input.getSubStreamById(i));
62
181k
    if (bool(subStream))
63
38.7k
      testRead(*subStream, buf);
64
65
181k
    const char *const name = input.subStreamName(i);
66
181k
    std::unique_ptr<librevenge::RVNGInputStream> namedSubStream(input.getSubStreamByName(name));
67
181k
    if (bool(namedSubStream))
68
38.7k
      testRead(*namedSubStream, buf);
69
181k
  }
70
4.37k
}
71
72
}
73
74
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */