Coverage Report

Created: 2025-08-03 06:03

/src/pjsip/tests/fuzz/fuzz-vpx.c
Line
Count
Source (jump to first uncovered line)
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
128
#define kMinInputLength 10
27
58
#define kMaxInputLength 5120
28
29
pj_pool_factory *mem;
30
31
int vpx_unpacketizer(const uint8_t *data, size_t size)
32
40
{
33
40
    int ret = 0;
34
40
    pj_pool_t *pool;
35
40
    pj_status_t status;
36
40
    pjmedia_vpx_packetizer_cfg cfg;
37
40
    pjmedia_vpx_packetizer *pktz;
38
40
    unsigned desc_len = 0;
39
40
40
    pool = pj_pool_create(mem, "vpx_test", 1000, 1000, NULL);
41
42
40
    pj_bzero(&cfg, sizeof(cfg));
43
44
40
    status = pjmedia_vpx_packetizer_create(pool, &cfg, &pktz);
45
46
40
    if (status == PJ_SUCCESS) {
47
0
        status = pjmedia_vpx_unpacketize(pktz, data, size, &desc_len);
48
0
    }
49
50
40
    pj_pool_release(pool);
51
52
40
    return ret;
53
40
}
54
55
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
56
64
{
57
64
    int ret = 0;
58
64
    uint8_t *data;
59
64
    pj_caching_pool caching_pool;
60
61
64
    if (Size < kMinInputLength || Size > kMaxInputLength) {
62
24
        return 1;
63
24
    }
64
65
    /* Add null termination for the data */
66
40
    data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
67
40
    memcpy((void *)data, (void *)Data, Size);
68
69
    /* Init */
70
40
    pj_init();
71
40
    pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
72
40
    pj_log_set_level(0);
73
74
40
    mem = &caching_pool.factory;
75
76
    /* Fuzz */
77
40
    ret = vpx_unpacketizer(data, Size);
78
79
40
    free(data);
80
40
    pj_caching_pool_destroy(&caching_pool);
81
82
40
    return ret;
83
64
}
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