Coverage Report

Created: 2026-03-07 07:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/xiph.h
Line
Count
Source
1
/*****************************************************************************
2
 * xiph.h: Xiph helpers
3
 *****************************************************************************
4
 * Copyright (C) 2010 Laurent Aimar
5
 *
6
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
#include <assert.h>
24
#include <limits.h>
25
472k
#define XIPH_MAX_HEADER_COUNT (256)
26
27
/* Temp ffmpeg vorbis format */
28
static inline bool xiph_IsLavcFormat(const void *extra, size_t i_extra,
29
                                     vlc_fourcc_t i_codec)
30
0
{
31
0
    switch(i_codec)
32
0
    {
33
0
        case VLC_CODEC_VORBIS:
34
0
            return i_extra >= 6 && GetWBE(extra) == 30;
35
0
        case VLC_CODEC_THEORA:
36
0
            return i_extra >= 6 && GetWBE(extra) == 42;
37
0
        default:
38
0
            return false;
39
0
    }
40
0
}
Unexecuted instantiation: essetup.c:xiph_IsLavcFormat
Unexecuted instantiation: ogg.c:xiph_IsLavcFormat
Unexecuted instantiation: opus_header.c:xiph_IsLavcFormat
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_IsLavcFormat(void const*, unsigned long, unsigned int)
Unexecuted instantiation: opus.c:xiph_IsLavcFormat
Unexecuted instantiation: vorbis.c:xiph_IsLavcFormat
Unexecuted instantiation: speex.c:xiph_IsLavcFormat
Unexecuted instantiation: theora.c:xiph_IsLavcFormat
41
42
static inline unsigned xiph_CountLavcHeaders(const void *p_extra, size_t i_extra)
43
0
{
44
0
    const uint8_t *p = (const uint8_t*) p_extra;
45
0
    const uint8_t *p_end = &p[i_extra];
46
0
    /* Check headers count */
47
0
    for (int i=0; i<3; i++)
48
0
    {
49
0
        if(p_end - p < 2)
50
0
            return 0;
51
0
        uint16_t i_size = GetWBE(p);
52
0
        if(&p[2U + i_size] > p_end)
53
0
            return 0;
54
0
        p += 2 + i_size;
55
0
    }
56
0
    return 3;
57
0
}
Unexecuted instantiation: essetup.c:xiph_CountLavcHeaders
Unexecuted instantiation: ogg.c:xiph_CountLavcHeaders
Unexecuted instantiation: opus_header.c:xiph_CountLavcHeaders
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_CountLavcHeaders(void const*, unsigned long)
Unexecuted instantiation: opus.c:xiph_CountLavcHeaders
Unexecuted instantiation: vorbis.c:xiph_CountLavcHeaders
Unexecuted instantiation: speex.c:xiph_CountLavcHeaders
Unexecuted instantiation: theora.c:xiph_CountLavcHeaders
58
59
static inline unsigned xiph_CountHeaders(const void *p_extra, size_t i_extra)
60
375k
{
61
375k
    const uint8_t *p = (const uint8_t*) p_extra;
62
375k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
375k
    if(1U + *p > i_extra)
66
0
        return 0;
67
375k
    return *p + 1;
68
375k
}
Unexecuted instantiation: essetup.c:xiph_CountHeaders
ogg.c:xiph_CountHeaders
Line
Count
Source
60
169k
{
61
169k
    const uint8_t *p = (const uint8_t*) p_extra;
62
169k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
169k
    if(1U + *p > i_extra)
66
0
        return 0;
67
169k
    return *p + 1;
68
169k
}
opus_header.c:xiph_CountHeaders
Line
Count
Source
60
7.13k
{
61
7.13k
    const uint8_t *p = (const uint8_t*) p_extra;
62
7.13k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
7.13k
    if(1U + *p > i_extra)
66
0
        return 0;
67
7.13k
    return *p + 1;
68
7.13k
}
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_CountHeaders(void const*, unsigned long)
opus.c:xiph_CountHeaders
Line
Count
Source
60
3.52k
{
61
3.52k
    const uint8_t *p = (const uint8_t*) p_extra;
62
3.52k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
3.52k
    if(1U + *p > i_extra)
66
0
        return 0;
67
3.52k
    return *p + 1;
68
3.52k
}
vorbis.c:xiph_CountHeaders
Line
Count
Source
60
146k
{
61
146k
    const uint8_t *p = (const uint8_t*) p_extra;
62
146k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
146k
    if(1U + *p > i_extra)
66
0
        return 0;
67
146k
    return *p + 1;
68
146k
}
speex.c:xiph_CountHeaders
Line
Count
Source
60
4.85k
{
61
4.85k
    const uint8_t *p = (const uint8_t*) p_extra;
62
4.85k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
4.85k
    if(1U + *p > i_extra)
66
0
        return 0;
67
4.85k
    return *p + 1;
68
4.85k
}
theora.c:xiph_CountHeaders
Line
Count
Source
60
43.7k
{
61
43.7k
    const uint8_t *p = (const uint8_t*) p_extra;
62
43.7k
    if (!i_extra)
63
0
        return 0;
64
    /* First byte is headers count */
65
43.7k
    if(1U + *p > i_extra)
66
0
        return 0;
67
43.7k
    return *p + 1;
68
43.7k
}
69
70
static inline unsigned xiph_CountUnknownHeaders(const void *p_extra, unsigned i_extra,
71
                                                vlc_fourcc_t i_codec)
72
0
{
73
0
    if (xiph_IsLavcFormat(p_extra, i_extra, i_codec))
74
0
        return xiph_CountLavcHeaders(p_extra, i_extra);
75
0
    else
76
0
        return xiph_CountHeaders(p_extra, i_extra);
77
0
}
Unexecuted instantiation: essetup.c:xiph_CountUnknownHeaders
Unexecuted instantiation: ogg.c:xiph_CountUnknownHeaders
Unexecuted instantiation: opus_header.c:xiph_CountUnknownHeaders
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_CountUnknownHeaders(void const*, unsigned int, unsigned int)
Unexecuted instantiation: opus.c:xiph_CountUnknownHeaders
Unexecuted instantiation: vorbis.c:xiph_CountUnknownHeaders
Unexecuted instantiation: speex.c:xiph_CountUnknownHeaders
Unexecuted instantiation: theora.c:xiph_CountUnknownHeaders
78
79
static inline int xiph_SplitLavcHeaders(size_t packet_size[],
80
                                        const void *packet[], size_t *packet_count,
81
                                        size_t i_extra, const void *p_extra)
82
0
{
83
0
    const uint8_t *current = (const uint8_t *)p_extra;
84
0
    const uint8_t *end = &current[i_extra];
85
0
    if (i_extra < 2)
86
0
        return VLC_EGENERIC;
87
0
    /* Parse the packet count and their sizes */
88
0
    const unsigned count = xiph_CountLavcHeaders(current, i_extra);
89
0
    if(count == 0)
90
0
        return VLC_EGENERIC;
91
0
    if (packet_count)
92
0
        *packet_count = count;
93
0
    /* count is trusted here (xiph_CountHeaders) */
94
0
    for (unsigned i=0; i < count; i++)
95
0
    {
96
0
        /* each payload is prefixed by word size */
97
0
        packet_size[i] = GetWBE(current);
98
0
        if(&current[2U + packet_size[i]] > end)
99
0
            return VLC_EGENERIC;
100
0
        packet[i] = current + 2;
101
0
        current += packet_size[i] + 2;
102
0
    }
103
0
    return VLC_SUCCESS;
104
0
}
Unexecuted instantiation: essetup.c:xiph_SplitLavcHeaders
Unexecuted instantiation: ogg.c:xiph_SplitLavcHeaders
Unexecuted instantiation: opus_header.c:xiph_SplitLavcHeaders
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_SplitLavcHeaders(unsigned long*, void const**, unsigned long*, unsigned long, void const*)
Unexecuted instantiation: opus.c:xiph_SplitLavcHeaders
Unexecuted instantiation: vorbis.c:xiph_SplitLavcHeaders
Unexecuted instantiation: speex.c:xiph_SplitLavcHeaders
Unexecuted instantiation: theora.c:xiph_SplitLavcHeaders
105
106
static inline int xiph_SplitHeaders(size_t packet_size[],
107
                                    const void *packet[], size_t *packet_count,
108
                                    size_t i_extra, const void *p_extra)
109
449k
{
110
449k
    const uint8_t *current = (const uint8_t *)p_extra;
111
449k
    const uint8_t *end = &current[i_extra];
112
449k
    if (i_extra < 1)
113
74.5k
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
375k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
375k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
375k
    if (packet_count)
121
375k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
375k
    ++current;
130
    /* read sizes for N-1 packets */
131
375k
    unsigned total_payload_minus_last = 0;
132
18.3M
    for (unsigned i = 0; i < count - 1; i++)
133
17.9M
    {
134
17.9M
        packet_size[i] = 0;
135
18.1M
        for (;;) {
136
18.1M
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
18.1M
            packet_size[i] += *current;
139
18.1M
            if (*current++ != 255)
140
17.9M
                break;
141
18.1M
        }
142
17.9M
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
17.9M
        total_payload_minus_last += packet_size[i];
145
17.9M
    }
146
375k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
18.3M
    for (unsigned i = 0; i < count - 1; i++)
150
17.9M
    {
151
17.9M
        packet[i] = current;
152
17.9M
        current += packet_size[i];
153
17.9M
    }
154
    /* Last packet is remaining size */
155
375k
    packet_size[count - 1] = end - current;
156
375k
    packet[count - 1] = current;
157
158
375k
    return VLC_SUCCESS;
159
375k
}
Unexecuted instantiation: essetup.c:xiph_SplitHeaders
ogg.c:xiph_SplitHeaders
Line
Count
Source
109
170k
{
110
170k
    const uint8_t *current = (const uint8_t *)p_extra;
111
170k
    const uint8_t *end = &current[i_extra];
112
170k
    if (i_extra < 1)
113
843
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
169k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
169k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
169k
    if (packet_count)
121
169k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
169k
    ++current;
130
    /* read sizes for N-1 packets */
131
169k
    unsigned total_payload_minus_last = 0;
132
17.7M
    for (unsigned i = 0; i < count - 1; i++)
133
17.5M
    {
134
17.5M
        packet_size[i] = 0;
135
17.6M
        for (;;) {
136
17.6M
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
17.6M
            packet_size[i] += *current;
139
17.6M
            if (*current++ != 255)
140
17.5M
                break;
141
17.6M
        }
142
17.5M
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
17.5M
        total_payload_minus_last += packet_size[i];
145
17.5M
    }
146
169k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
17.7M
    for (unsigned i = 0; i < count - 1; i++)
150
17.5M
    {
151
17.5M
        packet[i] = current;
152
17.5M
        current += packet_size[i];
153
17.5M
    }
154
    /* Last packet is remaining size */
155
169k
    packet_size[count - 1] = end - current;
156
169k
    packet[count - 1] = current;
157
158
169k
    return VLC_SUCCESS;
159
169k
}
opus_header.c:xiph_SplitHeaders
Line
Count
Source
109
7.13k
{
110
7.13k
    const uint8_t *current = (const uint8_t *)p_extra;
111
7.13k
    const uint8_t *end = &current[i_extra];
112
7.13k
    if (i_extra < 1)
113
0
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
7.13k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
7.13k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
7.13k
    if (packet_count)
121
7.13k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
7.13k
    ++current;
130
    /* read sizes for N-1 packets */
131
7.13k
    unsigned total_payload_minus_last = 0;
132
7.13k
    for (unsigned i = 0; i < count - 1; i++)
133
0
    {
134
0
        packet_size[i] = 0;
135
0
        for (;;) {
136
0
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
0
            packet_size[i] += *current;
139
0
            if (*current++ != 255)
140
0
                break;
141
0
        }
142
0
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
0
        total_payload_minus_last += packet_size[i];
145
0
    }
146
7.13k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
7.13k
    for (unsigned i = 0; i < count - 1; i++)
150
0
    {
151
0
        packet[i] = current;
152
0
        current += packet_size[i];
153
0
    }
154
    /* Last packet is remaining size */
155
7.13k
    packet_size[count - 1] = end - current;
156
7.13k
    packet[count - 1] = current;
157
158
7.13k
    return VLC_SUCCESS;
159
7.13k
}
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_SplitHeaders(unsigned long*, void const**, unsigned long*, unsigned long, void const*)
opus.c:xiph_SplitHeaders
Line
Count
Source
109
3.52k
{
110
3.52k
    const uint8_t *current = (const uint8_t *)p_extra;
111
3.52k
    const uint8_t *end = &current[i_extra];
112
3.52k
    if (i_extra < 1)
113
0
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
3.52k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
3.52k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
3.52k
    if (packet_count)
121
3.52k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
3.52k
    ++current;
130
    /* read sizes for N-1 packets */
131
3.52k
    unsigned total_payload_minus_last = 0;
132
7.04k
    for (unsigned i = 0; i < count - 1; i++)
133
3.52k
    {
134
3.52k
        packet_size[i] = 0;
135
3.52k
        for (;;) {
136
3.52k
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
3.52k
            packet_size[i] += *current;
139
3.52k
            if (*current++ != 255)
140
3.52k
                break;
141
3.52k
        }
142
3.52k
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
3.52k
        total_payload_minus_last += packet_size[i];
145
3.52k
    }
146
3.52k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
7.04k
    for (unsigned i = 0; i < count - 1; i++)
150
3.52k
    {
151
3.52k
        packet[i] = current;
152
3.52k
        current += packet_size[i];
153
3.52k
    }
154
    /* Last packet is remaining size */
155
3.52k
    packet_size[count - 1] = end - current;
156
3.52k
    packet[count - 1] = current;
157
158
3.52k
    return VLC_SUCCESS;
159
3.52k
}
vorbis.c:xiph_SplitHeaders
Line
Count
Source
109
219k
{
110
219k
    const uint8_t *current = (const uint8_t *)p_extra;
111
219k
    const uint8_t *end = &current[i_extra];
112
219k
    if (i_extra < 1)
113
73.1k
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
146k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
146k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
146k
    if (packet_count)
121
146k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
146k
    ++current;
130
    /* read sizes for N-1 packets */
131
146k
    unsigned total_payload_minus_last = 0;
132
438k
    for (unsigned i = 0; i < count - 1; i++)
133
292k
    {
134
292k
        packet_size[i] = 0;
135
315k
        for (;;) {
136
315k
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
315k
            packet_size[i] += *current;
139
315k
            if (*current++ != 255)
140
292k
                break;
141
315k
        }
142
292k
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
292k
        total_payload_minus_last += packet_size[i];
145
292k
    }
146
146k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
438k
    for (unsigned i = 0; i < count - 1; i++)
150
292k
    {
151
292k
        packet[i] = current;
152
292k
        current += packet_size[i];
153
292k
    }
154
    /* Last packet is remaining size */
155
146k
    packet_size[count - 1] = end - current;
156
146k
    packet[count - 1] = current;
157
158
146k
    return VLC_SUCCESS;
159
146k
}
speex.c:xiph_SplitHeaders
Line
Count
Source
109
4.85k
{
110
4.85k
    const uint8_t *current = (const uint8_t *)p_extra;
111
4.85k
    const uint8_t *end = &current[i_extra];
112
4.85k
    if (i_extra < 1)
113
0
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
4.85k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
4.85k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
4.85k
    if (packet_count)
121
4.85k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
4.85k
    ++current;
130
    /* read sizes for N-1 packets */
131
4.85k
    unsigned total_payload_minus_last = 0;
132
7.14k
    for (unsigned i = 0; i < count - 1; i++)
133
2.28k
    {
134
2.28k
        packet_size[i] = 0;
135
2.35k
        for (;;) {
136
2.35k
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
2.35k
            packet_size[i] += *current;
139
2.35k
            if (*current++ != 255)
140
2.28k
                break;
141
2.35k
        }
142
2.28k
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
2.28k
        total_payload_minus_last += packet_size[i];
145
2.28k
    }
146
4.85k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
7.14k
    for (unsigned i = 0; i < count - 1; i++)
150
2.28k
    {
151
2.28k
        packet[i] = current;
152
2.28k
        current += packet_size[i];
153
2.28k
    }
154
    /* Last packet is remaining size */
155
4.85k
    packet_size[count - 1] = end - current;
156
4.85k
    packet[count - 1] = current;
157
158
4.85k
    return VLC_SUCCESS;
159
4.85k
}
theora.c:xiph_SplitHeaders
Line
Count
Source
109
44.2k
{
110
44.2k
    const uint8_t *current = (const uint8_t *)p_extra;
111
44.2k
    const uint8_t *end = &current[i_extra];
112
44.2k
    if (i_extra < 1)
113
489
        return VLC_EGENERIC;
114
115
    /* Parse the packet count and their sizes */
116
43.7k
    const unsigned count = xiph_CountHeaders(current, i_extra);
117
43.7k
    if(count == 0)
118
0
        return VLC_EGENERIC;
119
120
43.7k
    if (packet_count)
121
43.7k
        *packet_count = count;
122
123
    /* - 1 byte (N-1) packets
124
     * - N-1 variable length payload sizes
125
     * - N-1 payloads
126
     * - Nth packet (remaining)  */
127
128
    /* skip count byte header */
129
43.7k
    ++current;
130
    /* read sizes for N-1 packets */
131
43.7k
    unsigned total_payload_minus_last = 0;
132
131k
    for (unsigned i = 0; i < count - 1; i++)
133
87.4k
    {
134
87.4k
        packet_size[i] = 0;
135
113k
        for (;;) {
136
113k
            if (current >= end)
137
0
                return VLC_EGENERIC;
138
113k
            packet_size[i] += *current;
139
113k
            if (*current++ != 255)
140
87.4k
                break;
141
113k
        }
142
87.4k
        if(UINT_MAX - total_payload_minus_last < packet_size[i])
143
0
            return VLC_EGENERIC;
144
87.4k
        total_payload_minus_last += packet_size[i];
145
87.4k
    }
146
43.7k
    if(current + total_payload_minus_last > end)
147
0
        return VLC_EGENERIC;
148
    /* set pointers for N-1 packets */
149
131k
    for (unsigned i = 0; i < count - 1; i++)
150
87.4k
    {
151
87.4k
        packet[i] = current;
152
87.4k
        current += packet_size[i];
153
87.4k
    }
154
    /* Last packet is remaining size */
155
43.7k
    packet_size[count - 1] = end - current;
156
43.7k
    packet[count - 1] = current;
157
158
43.7k
    return VLC_SUCCESS;
159
43.7k
}
160
161
static inline int xiph_PackHeaders(size_t *extra_size, void **extra,
162
                                   size_t packet_size[],
163
                                   const void *const packet[],
164
                                   size_t packet_count)
165
236k
{
166
236k
    if (packet_count <= 0 || packet_count > XIPH_MAX_HEADER_COUNT)
167
0
        return VLC_EGENERIC;
168
169
    /* Compute the size needed for the whole extra data */
170
236k
    size_t payload_size = 0;
171
236k
    size_t header_size = 1;
172
18.0M
    for (size_t i = 0; i < packet_count; i++) {
173
17.8M
        payload_size += packet_size[i];
174
17.8M
        if (i < packet_count - 1)
175
17.6M
            header_size += 1 + packet_size[i] / 255;
176
17.8M
    }
177
178
    /* */
179
236k
    *extra_size = header_size + payload_size;
180
236k
    *extra = malloc(*extra_size);
181
236k
    if (*extra == NULL)
182
0
        return VLC_ENOMEM;
183
184
    /* Write the header */
185
236k
    uint8_t *current = (uint8_t*)*extra;
186
236k
    *current++ = packet_count - 1;
187
17.8M
    for (size_t i = 0; i < packet_count - 1; i++) {
188
17.6M
        size_t t = packet_size[i];
189
17.6M
        for (;;) {
190
17.6M
            if (t >= 255) {
191
89.6k
                *current++ = 255;
192
89.6k
                t -= 255;
193
17.6M
            } else {
194
17.6M
                *current++ = t;
195
17.6M
                break;
196
17.6M
            }
197
17.6M
        }
198
17.6M
    }
199
200
    /* Copy the payloads */
201
18.0M
    for (size_t i = 0; i < packet_count; i++) {
202
17.8M
        if (packet_size[i] > 0) {
203
17.7M
            memcpy(current, packet[i], packet_size[i]);
204
17.7M
            current += packet_size[i];
205
17.7M
        }
206
17.8M
    }
207
236k
    assert(current == (uint8_t*)*extra + *extra_size);
208
236k
    return VLC_SUCCESS;
209
236k
}
Unexecuted instantiation: essetup.c:xiph_PackHeaders
ogg.c:xiph_PackHeaders
Line
Count
Source
165
221k
{
166
221k
    if (packet_count <= 0 || packet_count > XIPH_MAX_HEADER_COUNT)
167
0
        return VLC_EGENERIC;
168
169
    /* Compute the size needed for the whole extra data */
170
221k
    size_t payload_size = 0;
171
221k
    size_t header_size = 1;
172
18.0M
    for (size_t i = 0; i < packet_count; i++) {
173
17.8M
        payload_size += packet_size[i];
174
17.8M
        if (i < packet_count - 1)
175
17.5M
            header_size += 1 + packet_size[i] / 255;
176
17.8M
    }
177
178
    /* */
179
221k
    *extra_size = header_size + payload_size;
180
221k
    *extra = malloc(*extra_size);
181
221k
    if (*extra == NULL)
182
0
        return VLC_ENOMEM;
183
184
    /* Write the header */
185
221k
    uint8_t *current = (uint8_t*)*extra;
186
221k
    *current++ = packet_count - 1;
187
17.8M
    for (size_t i = 0; i < packet_count - 1; i++) {
188
17.5M
        size_t t = packet_size[i];
189
17.6M
        for (;;) {
190
17.6M
            if (t >= 255) {
191
89.6k
                *current++ = 255;
192
89.6k
                t -= 255;
193
17.5M
            } else {
194
17.5M
                *current++ = t;
195
17.5M
                break;
196
17.5M
            }
197
17.6M
        }
198
17.5M
    }
199
200
    /* Copy the payloads */
201
18.0M
    for (size_t i = 0; i < packet_count; i++) {
202
17.8M
        if (packet_size[i] > 0) {
203
17.7M
            memcpy(current, packet[i], packet_size[i]);
204
17.7M
            current += packet_size[i];
205
17.7M
        }
206
17.8M
    }
207
221k
    assert(current == (uint8_t*)*extra + *extra_size);
208
221k
    return VLC_SUCCESS;
209
221k
}
opus_header.c:xiph_PackHeaders
Line
Count
Source
165
14.2k
{
166
14.2k
    if (packet_count <= 0 || packet_count > XIPH_MAX_HEADER_COUNT)
167
0
        return VLC_EGENERIC;
168
169
    /* Compute the size needed for the whole extra data */
170
14.2k
    size_t payload_size = 0;
171
14.2k
    size_t header_size = 1;
172
35.6k
    for (size_t i = 0; i < packet_count; i++) {
173
21.3k
        payload_size += packet_size[i];
174
21.3k
        if (i < packet_count - 1)
175
7.13k
            header_size += 1 + packet_size[i] / 255;
176
21.3k
    }
177
178
    /* */
179
14.2k
    *extra_size = header_size + payload_size;
180
14.2k
    *extra = malloc(*extra_size);
181
14.2k
    if (*extra == NULL)
182
0
        return VLC_ENOMEM;
183
184
    /* Write the header */
185
14.2k
    uint8_t *current = (uint8_t*)*extra;
186
14.2k
    *current++ = packet_count - 1;
187
21.3k
    for (size_t i = 0; i < packet_count - 1; i++) {
188
7.13k
        size_t t = packet_size[i];
189
7.13k
        for (;;) {
190
7.13k
            if (t >= 255) {
191
0
                *current++ = 255;
192
0
                t -= 255;
193
7.13k
            } else {
194
7.13k
                *current++ = t;
195
7.13k
                break;
196
7.13k
            }
197
7.13k
        }
198
7.13k
    }
199
200
    /* Copy the payloads */
201
35.6k
    for (size_t i = 0; i < packet_count; i++) {
202
21.3k
        if (packet_size[i] > 0) {
203
21.3k
            memcpy(current, packet[i], packet_size[i]);
204
21.3k
            current += packet_size[i];
205
21.3k
        }
206
21.3k
    }
207
14.2k
    assert(current == (uint8_t*)*extra + *extra_size);
208
14.2k
    return VLC_SUCCESS;
209
14.2k
}
matroska_segment_parse.cpp:xiph_PackHeaders(unsigned long*, void**, unsigned long*, void const* const*, unsigned long)
Line
Count
Source
165
275
{
166
275
    if (packet_count <= 0 || packet_count > XIPH_MAX_HEADER_COUNT)
167
0
        return VLC_EGENERIC;
168
169
    /* Compute the size needed for the whole extra data */
170
275
    size_t payload_size = 0;
171
275
    size_t header_size = 1;
172
825
    for (size_t i = 0; i < packet_count; i++) {
173
550
        payload_size += packet_size[i];
174
550
        if (i < packet_count - 1)
175
275
            header_size += 1 + packet_size[i] / 255;
176
550
    }
177
178
    /* */
179
275
    *extra_size = header_size + payload_size;
180
275
    *extra = malloc(*extra_size);
181
275
    if (*extra == NULL)
182
0
        return VLC_ENOMEM;
183
184
    /* Write the header */
185
275
    uint8_t *current = (uint8_t*)*extra;
186
275
    *current++ = packet_count - 1;
187
550
    for (size_t i = 0; i < packet_count - 1; i++) {
188
275
        size_t t = packet_size[i];
189
343
        for (;;) {
190
343
            if (t >= 255) {
191
68
                *current++ = 255;
192
68
                t -= 255;
193
275
            } else {
194
275
                *current++ = t;
195
275
                break;
196
275
            }
197
343
        }
198
275
    }
199
200
    /* Copy the payloads */
201
825
    for (size_t i = 0; i < packet_count; i++) {
202
550
        if (packet_size[i] > 0) {
203
362
            memcpy(current, packet[i], packet_size[i]);
204
362
            current += packet_size[i];
205
362
        }
206
550
    }
207
275
    assert(current == (uint8_t*)*extra + *extra_size);
208
275
    return VLC_SUCCESS;
209
275
}
Unexecuted instantiation: opus.c:xiph_PackHeaders
Unexecuted instantiation: vorbis.c:xiph_PackHeaders
Unexecuted instantiation: speex.c:xiph_PackHeaders
Unexecuted instantiation: theora.c:xiph_PackHeaders
210
211
static inline int xiph_AppendHeaders(size_t *extra_size, void **extra,
212
                                     size_t size, const void *data)
213
236k
{
214
236k
    size_t packet_size[XIPH_MAX_HEADER_COUNT];
215
236k
    const void *packet[XIPH_MAX_HEADER_COUNT];
216
236k
    size_t count;
217
218
236k
    if (*extra_size > 0 && *extra) {
219
162k
        if (xiph_SplitHeaders(packet_size, packet, &count, *extra_size, *extra))
220
0
            return VLC_EGENERIC;
221
162k
    } else {
222
73.6k
        count = 0;
223
73.6k
    }
224
236k
    if (count >= XIPH_MAX_HEADER_COUNT)
225
525
        return VLC_EGENERIC;
226
227
235k
    void *old = *extra;
228
229
235k
    packet_size[count] = size;
230
235k
    packet[count]      = (void*)data;
231
235k
    if (xiph_PackHeaders(extra_size, extra, packet_size,
232
235k
                         packet, count + 1)) {
233
0
        *extra_size = 0;
234
0
        *extra      = NULL;
235
0
    }
236
237
235k
    free(old);
238
239
235k
    if (*extra_size == 0)
240
0
        return VLC_EGENERIC;
241
235k
    return VLC_SUCCESS;
242
235k
}
Unexecuted instantiation: essetup.c:xiph_AppendHeaders
ogg.c:xiph_AppendHeaders
Line
Count
Source
213
222k
{
214
222k
    size_t packet_size[XIPH_MAX_HEADER_COUNT];
215
222k
    const void *packet[XIPH_MAX_HEADER_COUNT];
216
222k
    size_t count;
217
218
222k
    if (*extra_size > 0 && *extra) {
219
155k
        if (xiph_SplitHeaders(packet_size, packet, &count, *extra_size, *extra))
220
0
            return VLC_EGENERIC;
221
155k
    } else {
222
66.5k
        count = 0;
223
66.5k
    }
224
222k
    if (count >= XIPH_MAX_HEADER_COUNT)
225
525
        return VLC_EGENERIC;
226
227
221k
    void *old = *extra;
228
229
221k
    packet_size[count] = size;
230
221k
    packet[count]      = (void*)data;
231
221k
    if (xiph_PackHeaders(extra_size, extra, packet_size,
232
221k
                         packet, count + 1)) {
233
0
        *extra_size = 0;
234
0
        *extra      = NULL;
235
0
    }
236
237
221k
    free(old);
238
239
221k
    if (*extra_size == 0)
240
0
        return VLC_EGENERIC;
241
221k
    return VLC_SUCCESS;
242
221k
}
opus_header.c:xiph_AppendHeaders
Line
Count
Source
213
14.2k
{
214
14.2k
    size_t packet_size[XIPH_MAX_HEADER_COUNT];
215
14.2k
    const void *packet[XIPH_MAX_HEADER_COUNT];
216
14.2k
    size_t count;
217
218
14.2k
    if (*extra_size > 0 && *extra) {
219
7.13k
        if (xiph_SplitHeaders(packet_size, packet, &count, *extra_size, *extra))
220
0
            return VLC_EGENERIC;
221
7.13k
    } else {
222
7.13k
        count = 0;
223
7.13k
    }
224
14.2k
    if (count >= XIPH_MAX_HEADER_COUNT)
225
0
        return VLC_EGENERIC;
226
227
14.2k
    void *old = *extra;
228
229
14.2k
    packet_size[count] = size;
230
14.2k
    packet[count]      = (void*)data;
231
14.2k
    if (xiph_PackHeaders(extra_size, extra, packet_size,
232
14.2k
                         packet, count + 1)) {
233
0
        *extra_size = 0;
234
0
        *extra      = NULL;
235
0
    }
236
237
14.2k
    free(old);
238
239
14.2k
    if (*extra_size == 0)
240
0
        return VLC_EGENERIC;
241
14.2k
    return VLC_SUCCESS;
242
14.2k
}
Unexecuted instantiation: matroska_segment_parse.cpp:xiph_AppendHeaders(unsigned long*, void**, unsigned long, void const*)
Unexecuted instantiation: opus.c:xiph_AppendHeaders
Unexecuted instantiation: vorbis.c:xiph_AppendHeaders
Unexecuted instantiation: speex.c:xiph_AppendHeaders
Unexecuted instantiation: theora.c:xiph_AppendHeaders