Coverage Report

Created: 2026-12-01 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openbabel/test/fuzz/fuzz_convert.cpp
Line
Count
Source
1
#include <openbabel/babelconfig.h>
2
#include <openbabel/mol.h>
3
#include <openbabel/obconversion.h>
4
#include <cstdlib>
5
#include <stdio.h>
6
#include <sstream>
7
8
// Vendored alongside this file (LLVM Apache-2.0 WITH LLVM-exception)
9
// so the harness compiles outside of an LLVM/libfuzzer toolchain — in
10
// particular under GCC, where the libfuzzer headers aren't shipped.
11
#include "FuzzedDataProvider.h"
12
13
1
std::vector<std::string> getAllFormats() {
14
1
    std::vector<std::string> formats;
15
1
    OpenBabel::OBPlugin::ListAsVector("formats", "ids", formats);
16
1
    std::sort(formats.begin(), formats.end());
17
1
    return formats;
18
1
}
19
20
20
const char *randomFormat(FuzzedDataProvider &fdp) {
21
20
    static std::vector<std::string> formats = getAllFormats();
22
20
    return formats[fdp.ConsumeIntegralInRange<int>(0, formats.size() - 1)].c_str();
23
20
}
24
25
10
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
26
10
    using namespace OpenBabel;
27
10
    obErrorLog.StopLogging();
28
29
10
    FuzzedDataProvider fdp(Data, Size);
30
10
    OBConversion conv;
31
10
    conv.SetInFormat(randomFormat(fdp));
32
10
    conv.SetOutFormat(randomFormat(fdp));
33
34
10
    std::ostringstream outStream;
35
10
    std::istringstream inStream(fdp.ConsumeRandomLengthString());
36
37
10
    try {
38
10
        conv.Convert(&inStream, &outStream);
39
10
    } catch (...) {
40
        // no error handling
41
0
    }
42
43
10
    return 0;
44
10
}