/src/gpac/testsuite/oss-fuzzers/fuzz_scene.c
Line | Count | Source |
1 | | #include <stdio.h> |
2 | | #include <unistd.h> |
3 | | #include <stdint.h> |
4 | | #include <string.h> |
5 | | #include <gpac/setup.h> |
6 | | #include <gpac/scenegraph.h> |
7 | | #include <gpac/bifs.h> |
8 | | #include <gpac/laser.h> |
9 | | #include <gpac/constants.h> |
10 | | |
11 | 2 | int LLVMFuzzerInitialize(int *argc, char ***argv) { |
12 | 2 | gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_QUIET); |
13 | 2 | return 0; |
14 | 2 | } |
15 | | |
16 | 29 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
17 | 29 | if (size < 10) return 0; |
18 | | |
19 | 29 | GF_SceneGraph *sg = gf_sg_new(); |
20 | 29 | if (!sg) return 0; |
21 | | |
22 | 29 | uint8_t type = data[0] % 2; |
23 | 29 | uint16_t es_id = (data[1] << 8) | data[2]; |
24 | 29 | uint32_t config_size = data[3] % 16; |
25 | 29 | if (config_size + 5 > size) config_size = 0; |
26 | | |
27 | 29 | const uint8_t *config = config_size ? &data[4] : NULL; |
28 | 29 | const uint8_t *payload = &data[4 + config_size]; |
29 | 29 | size_t payload_size = size - (4 + config_size); |
30 | | |
31 | 29 | if (type == 0) { |
32 | 4 | #ifndef GPAC_DISABLE_BIFS |
33 | 4 | GF_BifsDecoder *dec = gf_bifs_decoder_new(sg, GF_FALSE); |
34 | 4 | if (dec) { |
35 | 4 | if (config_size) { |
36 | 3 | gf_bifs_decoder_configure_stream(dec, es_id, (uint8_t *)config, config_size, GF_CODECID_BIFS); |
37 | 3 | } |
38 | 4 | gf_bifs_decode_au(dec, es_id, payload, payload_size, 0); |
39 | 4 | gf_bifs_decoder_del(dec); |
40 | 4 | } |
41 | 4 | #endif |
42 | 25 | } else { |
43 | 25 | #ifndef GPAC_DISABLE_LASER |
44 | 25 | GF_LASeRCodec *dec = gf_laser_decoder_new(sg); |
45 | 25 | if (dec) { |
46 | 25 | if (config_size) { |
47 | 24 | gf_laser_decoder_configure_stream(dec, es_id, (uint8_t *)config, config_size); |
48 | 24 | } |
49 | 25 | gf_laser_decode_au(dec, es_id, payload, payload_size); |
50 | 25 | gf_laser_decoder_del(dec); |
51 | 25 | } |
52 | 25 | #endif |
53 | 25 | } |
54 | | |
55 | 29 | gf_sg_del(sg); |
56 | | |
57 | 29 | return 0; |
58 | 29 | } |