Files
openbabel/test/fuzz/fuzz_convert.cpp
T
Geoff Hutchison 0f98db12a9 Add SECURITY policy and fuzz regression tests (#2882)
* Add initial security policy

* Add fuzz regression tests (for CVE reports) and ASAN tests
* Add public OSS-Fuzz testcases for reproducing bugs
* Limit sanitize on InChI for now
* Fix bugs exposed with ASAN / UBSAN tests
* Fixes for OSS-Fuzz test cases

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>

---------

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
2026-05-09 12:28:57 -04:00

45 lines
1.3 KiB
C++

#include <openbabel/babelconfig.h>
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
// Vendored alongside this file (LLVM Apache-2.0 WITH LLVM-exception)
// so the harness compiles outside of an LLVM/libfuzzer toolchain — in
// particular under GCC, where the libfuzzer headers aren't shipped.
#include "FuzzedDataProvider.h"
std::vector<std::string> getAllFormats() {
std::vector<std::string> formats;
OpenBabel::OBPlugin::ListAsVector("formats", "ids", formats);
std::sort(formats.begin(), formats.end());
return formats;
}
const char *randomFormat(FuzzedDataProvider &fdp) {
static std::vector<std::string> formats = getAllFormats();
return formats[fdp.ConsumeIntegralInRange<int>(0, formats.size() - 1)].c_str();
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
using namespace OpenBabel;
obErrorLog.StopLogging();
FuzzedDataProvider fdp(Data, Size);
OBConversion conv;
conv.SetInFormat(randomFormat(fdp));
conv.SetOutFormat(randomFormat(fdp));
std::ostringstream outStream;
std::istringstream inStream(fdp.ConsumeRandomLengthString());
try {
conv.Convert(&inStream, &outStream);
} catch (...) {
// no error handling
}
return 0;
}