FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/xiph.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 24 29 82.8%
Functions: 1 1 100.0%
Branches: 14 22 63.6%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2007 The FFmpeg Project
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <limits.h>
22 #include "libavutil/error.h"
23 #include "libavutil/intreadwrite.h"
24 #include "xiph.h"
25
26 117 int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size,
27 int first_header_size, const uint8_t *header_start[3],
28 int header_len[3])
29 {
30 int i;
31
32
3/4
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 113 times.
121 if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) {
33 4 int overall_len = 6;
34
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 for (i=0; i<3; i++) {
35 12 header_len[i] = AV_RB16(extradata);
36 12 extradata += 2;
37 12 header_start[i] = extradata;
38 12 extradata += header_len[i];
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (overall_len > extradata_size - header_len[i])
40 return AVERROR_INVALIDDATA;
41 12 overall_len += header_len[i];
42 }
43
3/6
✓ Branch 0 taken 113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 113 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 113 times.
✗ Branch 5 not taken.
113 } else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) {
44 113 int overall_len = 3;
45 113 extradata++;
46
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 113 times.
339 for (i=0; i<2; i++, extradata++) {
47 226 header_len[i] = 0;
48
2/4
✓ Branch 0 taken 226 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 226 times.
226 for (; overall_len < extradata_size && *extradata==0xff; extradata++) {
49 header_len[i] += 0xff;
50 overall_len += 0xff + 1;
51 }
52 226 header_len[i] += *extradata;
53 226 overall_len += *extradata;
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 226 times.
226 if (overall_len > extradata_size)
55 return AVERROR_INVALIDDATA;
56 }
57 113 header_len[2] = extradata_size - overall_len;
58 113 header_start[0] = extradata;
59 113 header_start[1] = header_start[0] + header_len[0];
60 113 header_start[2] = header_start[1] + header_len[1];
61 } else {
62 return -1;
63 }
64 117 return 0;
65 }
66