Chris@69
|
1 /* Copyright (c) 2012 Xiph.Org Foundation
|
Chris@69
|
2 Written by Jüri Aedla and Ralph Giles */
|
Chris@69
|
3 /*
|
Chris@69
|
4 Redistribution and use in source and binary forms, with or without
|
Chris@69
|
5 modification, are permitted provided that the following conditions
|
Chris@69
|
6 are met:
|
Chris@69
|
7
|
Chris@69
|
8 - Redistributions of source code must retain the above copyright
|
Chris@69
|
9 notice, this list of conditions and the following disclaimer.
|
Chris@69
|
10
|
Chris@69
|
11 - Redistributions in binary form must reproduce the above copyright
|
Chris@69
|
12 notice, this list of conditions and the following disclaimer in the
|
Chris@69
|
13 documentation and/or other materials provided with the distribution.
|
Chris@69
|
14
|
Chris@69
|
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@69
|
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@69
|
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@69
|
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
Chris@69
|
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
Chris@69
|
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
Chris@69
|
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
Chris@69
|
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
Chris@69
|
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
Chris@69
|
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
Chris@69
|
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@69
|
26 */
|
Chris@69
|
27
|
Chris@69
|
28 /* Check for overflow in reading the padding length.
|
Chris@69
|
29 * http://lists.xiph.org/pipermail/opus/2012-November/001834.html
|
Chris@69
|
30 */
|
Chris@69
|
31
|
Chris@69
|
32 #include <stdio.h>
|
Chris@69
|
33 #include <stdlib.h>
|
Chris@69
|
34 #include <string.h>
|
Chris@69
|
35 #include "opus.h"
|
Chris@69
|
36 #include "test_opus_common.h"
|
Chris@69
|
37
|
Chris@69
|
38 #define PACKETSIZE 16909318
|
Chris@69
|
39 #define CHANNELS 2
|
Chris@69
|
40 #define FRAMESIZE 5760
|
Chris@69
|
41
|
Chris@69
|
42 int test_overflow(void)
|
Chris@69
|
43 {
|
Chris@69
|
44 OpusDecoder *decoder;
|
Chris@69
|
45 int result;
|
Chris@69
|
46 int error;
|
Chris@69
|
47
|
Chris@69
|
48 unsigned char *in = malloc(PACKETSIZE);
|
Chris@69
|
49 opus_int16 *out = malloc(FRAMESIZE*CHANNELS*sizeof(*out));
|
Chris@69
|
50
|
Chris@69
|
51 fprintf(stderr, " Checking for padding overflow... ");
|
Chris@69
|
52 if (!in || !out) {
|
Chris@69
|
53 fprintf(stderr, "FAIL (out of memory)\n");
|
Chris@69
|
54 return -1;
|
Chris@69
|
55 }
|
Chris@69
|
56 in[0] = 0xff;
|
Chris@69
|
57 in[1] = 0x41;
|
Chris@69
|
58 memset(in + 2, 0xff, PACKETSIZE - 3);
|
Chris@69
|
59 in[PACKETSIZE-1] = 0x0b;
|
Chris@69
|
60
|
Chris@69
|
61 decoder = opus_decoder_create(48000, CHANNELS, &error);
|
Chris@69
|
62 result = opus_decode(decoder, in, PACKETSIZE, out, FRAMESIZE, 0);
|
Chris@69
|
63 opus_decoder_destroy(decoder);
|
Chris@69
|
64
|
Chris@69
|
65 free(in);
|
Chris@69
|
66 free(out);
|
Chris@69
|
67
|
Chris@69
|
68 if (result != OPUS_INVALID_PACKET) {
|
Chris@69
|
69 fprintf(stderr, "FAIL!\n");
|
Chris@69
|
70 test_failed();
|
Chris@69
|
71 }
|
Chris@69
|
72
|
Chris@69
|
73 fprintf(stderr, "OK.\n");
|
Chris@69
|
74
|
Chris@69
|
75 return 1;
|
Chris@69
|
76 }
|
Chris@69
|
77
|
Chris@69
|
78 int main(void)
|
Chris@69
|
79 {
|
Chris@69
|
80 const char *oversion;
|
Chris@69
|
81 int tests = 0;;
|
Chris@69
|
82
|
Chris@69
|
83 iseed = 0;
|
Chris@69
|
84 oversion = opus_get_version_string();
|
Chris@69
|
85 if (!oversion) test_failed();
|
Chris@69
|
86 fprintf(stderr, "Testing %s padding.\n", oversion);
|
Chris@69
|
87
|
Chris@69
|
88 tests += test_overflow();
|
Chris@69
|
89
|
Chris@69
|
90 fprintf(stderr, "All padding tests passed.\n");
|
Chris@69
|
91
|
Chris@69
|
92 return 0;
|
Chris@69
|
93 }
|