Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-10-27 21:42:48 +0400
committerGregory Maxwell <greg@xiph.org>2012-10-27 21:42:48 +0400
commitde95da9bf1c98b80368cf643e3b7da45f3ca108b (patch)
tree9c24769c3c7d414a07294a1931781535bccb79ca /src
parent6930d90c341fca347f3fdc1e10c43f3265174aed (diff)
Fix several issues with multistream argument validation.
As reported by Mark Warner opus_multistream_*_create were depending on the behavior of malloc(0) in order to correctly report some kinds of argument errors. Bad arguments could be incorrectly reported as allocation failures. This changes multistream to explicitly check the arguments like the single stream _create functions. The unit tests were enough to catch this on systems where malloc(0) returns NULL but didn't catch it on other systems because the later _init call would catch the bad arguments and trigger the correct error if and only if the malloc didn't return a null pointer. In multistream_encoder_init failures of the internal non-multistream init calls were not being caught and propagated. Decode didn't have this problem. This propagates the errors and adds additional tests (the multistream encoder api is sill under tested) that would have detected this error. Plus add some stronger tests for things like error==NULL for the _create functions that take a pointer for error output.
Diffstat (limited to 'src')
-rw-r--r--src/opus_multistream.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/opus_multistream.c b/src/opus_multistream.c
index 646e9b64..9c427b5d 100644
--- a/src/opus_multistream.c
+++ b/src/opus_multistream.c
@@ -159,7 +159,7 @@ int opus_multistream_encoder_init(
{
int coupled_size;
int mono_size;
- int i;
+ int i, ret;
char *ptr;
if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
@@ -180,12 +180,14 @@ int opus_multistream_encoder_init(
for (i=0;i<st->layout.nb_coupled_streams;i++)
{
- opus_encoder_init((OpusEncoder*)ptr, Fs, 2, application);
+ ret = opus_encoder_init((OpusEncoder*)ptr, Fs, 2, application);
+ if(ret!=OPUS_OK)return ret;
ptr += align(coupled_size);
}
for (;i<st->layout.nb_streams;i++)
{
- opus_encoder_init((OpusEncoder*)ptr, Fs, 1, application);
+ ret = opus_encoder_init((OpusEncoder*)ptr, Fs, 1, application);
+ if(ret!=OPUS_OK)return ret;
ptr += align(mono_size);
}
return OPUS_OK;
@@ -202,7 +204,15 @@ OpusMSEncoder *opus_multistream_encoder_create(
)
{
int ret;
- OpusMSEncoder *st = (OpusMSEncoder *)opus_alloc(opus_multistream_encoder_get_size(streams, coupled_streams));
+ OpusMSEncoder *st;
+ if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
+ (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0))
+ {
+ if (error)
+ *error = OPUS_BAD_ARG;
+ return NULL;
+ }
+ st = (OpusMSEncoder *)opus_alloc(opus_multistream_encoder_get_size(streams, coupled_streams));
if (st==NULL)
{
if (error)
@@ -649,7 +659,15 @@ OpusMSDecoder *opus_multistream_decoder_create(
)
{
int ret;
- OpusMSDecoder *st = (OpusMSDecoder *)opus_alloc(opus_multistream_decoder_get_size(streams, coupled_streams));
+ OpusMSDecoder *st;
+ if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
+ (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0))
+ {
+ if (error)
+ *error = OPUS_BAD_ARG;
+ return NULL;
+ }
+ st = (OpusMSDecoder *)opus_alloc(opus_multistream_decoder_get_size(streams, coupled_streams));
if (st==NULL)
{
if (error)
@@ -665,8 +683,6 @@ OpusMSDecoder *opus_multistream_decoder_create(
st = NULL;
}
return st;
-
-
}
typedef void (*opus_copy_channel_out_func)(