Debian Codegraph @

Xpjproject/tests/fuzz/fuzz-vpx.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2023 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <stdlib.h>
21
22 #include <pjlib.h>
23 #include <pjmedia-codec/vpx_packetizer.h>
24
25 #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
26 #define kMinInputLength 10
27 #define kMaxInputLength 5120
28
29 pj_pool_factory *mem;
30
31 int vpx_unpacketizer(const uint8_t *data, size_t size)
32 {
33 int ret = 0;
34 pj_pool_t *pool;
35 pj_status_t status;
36 pjmedia_vpx_packetizer_cfg cfg;
37 pjmedia_vpx_packetizer *pktz;
38 unsigned desc_len = 0;
39
40 pool = pj_pool_create(mem, "vpx_test", 1000, 1000, NULL);
41
42 pj_bzero(&cfg, sizeof(cfg));
43
44 status = pjmedia_vpx_packetizer_create(pool, &cfg, &pktz);
45
46 if (status == PJ_SUCCESS) {
47 status = pjmedia_vpx_unpacketize(pktz, data, size, &desc_len);
48 }
49
50 pj_pool_release(pool);
51
52 return ret;
53 }
54
55 extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
56 {
57 int ret = 0;
58 uint8_t *data;
59 pj_caching_pool caching_pool;
60
61 if (Size < kMinInputLength || Size > kMaxInputLength) {
62 return 1;
63 }
64
65 /* Add null termination for the data */
66 data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
67 memcpy((void *)data, (void *)Data, Size);
68
69 /* Init */
70 pj_init();
71 pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
72 pj_log_set_level(0);
73
74 mem = &caching_pool.factory;
75
76 /* Fuzz */
77 ret = vpx_unpacketizer(data, Size);
78
79 free(data);
80 pj_caching_pool_destroy(&caching_pool);
81
82 return ret;
83 }
84 #else
85 extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
86 {
87 PJ_UNUSED_ARG(Data);
88 PJ_UNUSED_ARG(Size);
89 return 0;
90 }
91 #endif