Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Side by Side Diff: tests/test_opus_padding.c

Issue 66503002: Updating Opus 1.1 Beta (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « autogen.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* Check for overflow in reading the padding length.
2 * Example by Jüri Aedla and Ralph Giles
3 * http://lists.xiph.org/pipermail/opus/2012-November/001834.html
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "opus.h"
10 #include "test_opus_common.h"
11
12 #define PACKETSIZE 16909318
13 #define CHANNELS 2
14 #define FRAMESIZE 5760
15
16 int test_overflow(void)
17 {
18 OpusDecoder *decoder;
19 int result;
20 int error;
21
22 unsigned char *in = malloc(PACKETSIZE);
23 opus_int16 *out = malloc(FRAMESIZE*CHANNELS*sizeof(*out));
24
25 fprintf(stderr, " Checking for padding overflow... ");
26 if (!in || !out) {
27 fprintf(stderr, "FAIL (out of memory)\n");
28 return -1;
29 }
30 in[0] = 0xff;
31 in[1] = 0x41;
32 memset(in + 2, 0xff, PACKETSIZE - 3);
33 in[PACKETSIZE-1] = 0x0b;
34
35 decoder = opus_decoder_create(48000, CHANNELS, &error);
36 result = opus_decode(decoder, in, PACKETSIZE, out, FRAMESIZE, 0);
37 opus_decoder_destroy(decoder);
38
39 free(in);
40 free(out);
41
42 if (result != OPUS_INVALID_PACKET) {
43 fprintf(stderr, "FAIL!\n");
44 test_failed();
45 }
46
47 fprintf(stderr, "OK.\n");
48
49 return 1;
50 }
51
52 int main(void)
53 {
54 const char *oversion;
55 int tests = 0;;
56
57 iseed = 0;
58 oversion = opus_get_version_string();
59 if (!oversion) test_failed();
60 fprintf(stderr, "Testing %s padding.\n", oversion);
61
62 tests += test_overflow();
63
64 fprintf(stderr, "All padding tests passed.\n");
65
66 return 0;
67 }
OLDNEW
« no previous file with comments | « autogen.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698