summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Harris <mark.hsj@gmail.com>2016-11-05 21:32:28 -0700
committerMark Harris <mark.hsj@gmail.com>2016-11-05 21:32:28 -0700
commitd74fa2785a7ca3d25767e90bbc09c11cfcf07349 (patch)
treef71fbd535bcfcb31125e136576bb8ab67ee3ab1d
parent132ed59464dccaae8f1e2f13f168763e99f85d17 (diff)
downloadopus-d74fa2785a7ca3d25767e90bbc09c11cfcf07349.tar.gz
Fix crash on bad encoder frame_size argument
-rw-r--r--src/opus_encoder.c12
-rw-r--r--tests/test_opus_encode.c1
2 files changed, 11 insertions, 2 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index 4c84efec..226a2de6 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -2171,7 +2171,11 @@ opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int analysis_fra
ALLOC_STACK;
frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs);
-
+ if (frame_size <= 0)
+ {
+ RESTORE_STACK;
+ return OPUS_BAD_ARG;
+ }
ALLOC(in, frame_size*st->channels, opus_int16);
for (i=0;i<frame_size*st->channels;i++)
@@ -2202,7 +2206,11 @@ opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int analysis_fram
ALLOC_STACK;
frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs);
-
+ if (frame_size <= 0)
+ {
+ RESTORE_STACK;
+ return OPUS_BAD_ARG;
+ }
ALLOC(in, frame_size*st->channels, float);
for (i=0;i<frame_size*st->channels;i++)
diff --git a/tests/test_opus_encode.c b/tests/test_opus_encode.c
index ae54bb60..b8427138 100644
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -384,6 +384,7 @@ int run_test1(int no_fuzz)
if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(-2))!=OPUS_BAD_ARG)test_failed();
+ if(opus_encode(enc, inbuf, 500, packet, MAX_PACKET)!=OPUS_BAD_ARG)test_failed();
for(rc=0;rc<3;rc++)
{