SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
fuzz_sdds3.cc
Go to the documentation of this file.
1/**
2 * @file fuzz_sdds3.cc
3 * @brief In-process fuzz harness for the standalone C++ SDDS parser and decoders.
4 *
5 * @details Exercises layout parsing and page decoding from caller-owned memory
6 * with conservative resource limits.
7 *
8 * @copyright
9 * - (c) 2026 The University of Chicago
10 *
11 * @license
12 * This file is distributed under the terms of the Software License Agreement
13 * found in the file LICENSE included with this distribution.
14 */
15
16#include "SDDS.hpp"
17
18#include <cstddef>
19#include <cstdint>
20
21#if defined(SDDSPP_FUZZ_STANDALONE)
22# include <fstream>
23# include <iterator>
24# include <string>
25# include <vector>
26#endif
27
28extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) {
29 sdds::ReaderOptions options;
30 options.recovery = sdds::RecoveryMode::Strict;
31 options.compression = sdds::Compression::None;
32 options.limits.maxRows = 10000;
33 options.limits.maxElements = 100000;
34 options.limits.maxStringBytes = 65536;
35 options.limits.maxLayoutCommandBytes = 65536;
36 options.limits.maxDecompressedBytes = 1024U * 1024U;
37 options.limits.maxIncludeDepth = 0;
38 options.limits.maxPageIndexEntries = 1024;
39 try {
40 auto reader = sdds::Reader::fromSource(sdds::inputFromMemory(data, size),
41 "fuzz-input", options);
42 sdds::ReadRequest request;
43 request.rows.stride = 3;
44 while (reader.next(request)) {}
45 reader.close();
46 } catch (const sdds::Error &) {
47 } catch (const std::exception &) {
48 }
49 return 0;
50}
51
52#if defined(SDDSPP_FUZZ_STANDALONE)
53int main(int argc, char **argv) {
54 for (int argument = 1; argument < argc; ++argument) {
55 std::ifstream input(argv[argument], std::ios::binary);
56 const std::vector<std::uint8_t> bytes((std::istreambuf_iterator<char>(input)),
57 std::istreambuf_iterator<char>());
58 LLVMFuzzerTestOneInput(bytes.data(), bytes.size());
59 }
60 return 0;
61}
62#endif