Chris@69: /* Copyright (c) 2012 Xiph.Org Foundation Chris@69: Written by Jüri Aedla and Ralph Giles */ Chris@69: /* Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: Chris@69: - Redistributions of source code must retain the above copyright Chris@69: notice, this list of conditions and the following disclaimer. Chris@69: Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@69: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@69: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@69: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER Chris@69: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@69: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@69: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@69: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@69: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@69: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@69: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@69: */ Chris@69: Chris@69: /* Check for overflow in reading the padding length. Chris@69: * http://lists.xiph.org/pipermail/opus/2012-November/001834.html Chris@69: */ Chris@69: Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #include "opus.h" Chris@69: #include "test_opus_common.h" Chris@69: Chris@69: #define PACKETSIZE 16909318 Chris@69: #define CHANNELS 2 Chris@69: #define FRAMESIZE 5760 Chris@69: Chris@69: int test_overflow(void) Chris@69: { Chris@69: OpusDecoder *decoder; Chris@69: int result; Chris@69: int error; Chris@69: Chris@69: unsigned char *in = malloc(PACKETSIZE); Chris@69: opus_int16 *out = malloc(FRAMESIZE*CHANNELS*sizeof(*out)); Chris@69: Chris@69: fprintf(stderr, " Checking for padding overflow... "); Chris@69: if (!in || !out) { Chris@69: fprintf(stderr, "FAIL (out of memory)\n"); Chris@69: return -1; Chris@69: } Chris@69: in[0] = 0xff; Chris@69: in[1] = 0x41; Chris@69: memset(in + 2, 0xff, PACKETSIZE - 3); Chris@69: in[PACKETSIZE-1] = 0x0b; Chris@69: Chris@69: decoder = opus_decoder_create(48000, CHANNELS, &error); Chris@69: result = opus_decode(decoder, in, PACKETSIZE, out, FRAMESIZE, 0); Chris@69: opus_decoder_destroy(decoder); Chris@69: Chris@69: free(in); Chris@69: free(out); Chris@69: Chris@69: if (result != OPUS_INVALID_PACKET) { Chris@69: fprintf(stderr, "FAIL!\n"); Chris@69: test_failed(); Chris@69: } Chris@69: Chris@69: fprintf(stderr, "OK.\n"); Chris@69: Chris@69: return 1; Chris@69: } Chris@69: Chris@69: int main(void) Chris@69: { Chris@69: const char *oversion; Chris@69: int tests = 0;; Chris@69: Chris@69: iseed = 0; Chris@69: oversion = opus_get_version_string(); Chris@69: if (!oversion) test_failed(); Chris@69: fprintf(stderr, "Testing %s padding.\n", oversion); Chris@69: Chris@69: tests += test_overflow(); Chris@69: Chris@69: fprintf(stderr, "All padding tests passed.\n"); Chris@69: Chris@69: return 0; Chris@69: }