1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | #include <stdio.h> |
33 | #include <stdlib.h> |
34 | #include <string.h> |
35 | #include "opus.h" |
36 | #include "test_opus_common.h" |
37 | |
38 | #define PACKETSIZE16909318 16909318 |
39 | #define CHANNELS2 2 |
40 | #define FRAMESIZE5760 5760 |
41 | |
42 | int test_overflow(void) |
43 | { |
44 | OpusDecoder *decoder; |
45 | int result; |
46 | int error; |
47 | |
48 | unsigned char *in = malloc(PACKETSIZE16909318); |
49 | opus_int16 *out = malloc(FRAMESIZE5760*CHANNELS2*sizeof(*out)); |
50 | |
51 | fprintf(stderrstderr, " Checking for padding overflow... "); |
52 | if (!in || !out) { |
53 | fprintf(stderrstderr, "FAIL (out of memory)\n"); |
54 | return -1; |
55 | } |
56 | in[0] = 0xff; |
57 | in[1] = 0x41; |
58 | memset(in + 2, 0xff, PACKETSIZE16909318 - 3); |
59 | in[PACKETSIZE16909318-1] = 0x0b; |
60 | |
61 | decoder = opus_decoder_create(48000, CHANNELS2, &error); |
62 | result = opus_decode(decoder, in, PACKETSIZE16909318, out, FRAMESIZE5760, 0); |
63 | opus_decoder_destroy(decoder); |
64 | |
65 | free(in); |
66 | free(out); |
67 | |
68 | if (result != OPUS_INVALID_PACKET-4) { |
69 | fprintf(stderrstderr, "FAIL!\n"); |
70 | test_failed()_test_failed("tests/test_opus_padding.c", 70);; |
71 | } |
72 | |
73 | fprintf(stderrstderr, "OK.\n"); |
74 | |
75 | return 1; |
76 | } |
77 | |
78 | int main(void) |
79 | { |
80 | const char *oversion; |
81 | int tests = 0;; |
82 | |
83 | iseed = 0; |
84 | oversion = opus_get_version_string(); |
85 | if (!oversion) test_failed()_test_failed("tests/test_opus_padding.c", 85);; |
86 | fprintf(stderrstderr, "Testing %s padding.\n", oversion); |
87 | |
88 | tests += test_overflow(); |
| Value stored to 'tests' is never read |
89 | |
90 | fprintf(stderrstderr, "All padding tests passed.\n"); |
91 | |
92 | return 0; |
93 | } |