Debian Codegraph @

fuzzing/box_fuzzer.cc

raw
1 /*
2 * HEIF codec.
3 * Copyright (c) 2017 struktur AG, Joachim Bauch <[email protected]>
4 *
5 * This file is part of libheif.
6 *
7 * libheif is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * libheif is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libheif. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <sstream>
22
23 #include "box.h"
24 #include "bitstream.h"
25 #include "context.h"
26 #include "logging.h"
27
28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
29 {
30 auto reader = std::make_shared<StreamReader_memory>(data, size, false);
31
32 // --- OSS-Fuzz assumes a bug if the allocated memory exceeds 2560 MB.
33 // Set a lower allocation limit to prevent this.
34
35 // Use a context for tracking the memory usage and set the reduced limit.
36 HeifContext ctx;
37 ctx.get_security_limits()->max_total_memory = UINT64_C(2) * 1024 * 1024 * 1024;
38
39 BitstreamRange range(reader, size);
40 for (;;) {
41 std::shared_ptr<Box> box;
42 Error error = Box::read(range, &box, ctx.get_security_limits());
43 if (error != Error::Ok || range.error()) {
44 break;
45 }
46
47 box->get_type();
48 box->get_type_string();
49 Indent indent;
50 box->dump(indent);
51 }
52
53 return 0;
54 }