Project
Loading...
Searching...
No Matches
fuzz_RootFile.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12// libFuzzer target: a whole file in memory, read through every layer. Malformed
13// input must end in a FormatError; any other exception, crash, hang or
14// out-of-bounds access is a bug. Seed it with small corpus files.
15
17#include "AODNative/Container.h"
18#include "AODNative/Errors.h"
19#include "../RootFraming.h"
20
21using namespace o2::aod::native;
22
23namespace
24{
25// Decoding allocates what the file says it holds; keep that within the
26// fuzzer's memory limit. The reader itself has no such limit.
27constexpr int64_t kMaxDecodedBytes = 64 * 1024 * 1024;
28
29bool small(TreeInfo const& tree)
30{
31 int64_t total = 0;
32 for (auto& b : tree.branches) {
33 if (b.entries < 0 || b.fixedLen < 0 || b.entries > kMaxDecodedBytes || b.fixedLen > 1024) {
34 return false;
35 }
36 total += b.entries * b.fixedLen * 8;
37 }
38 return total < kMaxDecodedBytes;
39}
40} // namespace
41
42extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
43{
44 auto source = std::make_shared<test::MemoryByteSource>(std::vector<uint8_t>(data, data + size));
45 try {
46 RootFile file{source};
47 file.topKeys();
48 file.readStringMap("metaData");
49 for (auto& df : file.dataFrames()) {
50 try {
51 for (auto& key : file.keysOf(df)) {
52 if (key.className != "TTree") {
53 continue;
54 }
55 try {
56 auto tree = file.readTree(key);
57 if (small(tree)) {
59 }
60 } catch (FormatError const&) {
61 }
62 }
63 } catch (FormatError const&) {
64 }
65 }
66 } catch (FormatError const&) {
67 }
68 return 0;
69}
StringRef key
int LLVMFuzzerTestOneInput(uint8_t const *data, size_t size)
GLsizeiptr size
Definition glcorearb.h:659
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLboolean * data
Definition glcorearb.h:298
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
arrow::Result< std::shared_ptr< arrow::RecordBatch > > readTree(ByteSource &source, TreeInfo const &tree, Options const &options, arrow::MemoryPool *pool=arrow::default_memory_pool())
Reads a whole tree into heap memory: plan, execute, wrap.
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))