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

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2016-07-04 08:29:23 +0300
committerJean-Marc Valin <jmvalin@jmvalin.ca>2016-07-04 08:29:23 +0300
commit328953e1896432bc700b9b5c69ae2987c5d752f4 (patch)
tree10f574c6f6e3c42644728f352747ce97d78171ea
parentf6f8487b76f234437e7d4c2831e630d9d06cb074 (diff)
Making calls to opus_packet_pad() on a bad packet return OPUS_INVALID_PACKET
We were previously returning OPUS_BAD_ARG because the failure was only detected in opus_repacketizer_out_range_impl() rather than in opus_repacketizer_cat(). Checking the return value from opus_repacketizer_cat() also addresses the last outstanding Coverity defect.
-rw-r--r--src/opus_multistream_encoder.c7
-rw-r--r--src/repacketizer.c4
-rw-r--r--tests/test_opus_api.c4
3 files changed, 11 insertions, 4 deletions
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c
index 9a7ea95e..389a8477 100644
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -968,6 +968,7 @@ static int opus_multistream_encode_native
int len;
int curr_max;
int c1, c2;
+ int ret;
opus_repacketizer_init(&rp);
enc = (OpusEncoder*)ptr;
@@ -1027,7 +1028,11 @@ static int opus_multistream_encode_native
/* We need to use the repacketizer to add the self-delimiting lengths
while taking into account the fact that the encoder can now return
more than one frame at a time (e.g. 60 ms CELT-only) */
- opus_repacketizer_cat(&rp, tmp_data, len);
+ ret = opus_repacketizer_cat(&rp, tmp_data, len);
+ /* If the opus_repacketizer_cat() fails, then something's seriously wrong
+ with the encoder. */
+ if (ret != OPUS_OK)
+ return OPUS_INTERNAL_ERROR;
len = opus_repacketizer_out_range_impl(&rp, 0, opus_repacketizer_get_nb_frames(&rp),
data, max_data_bytes-tot_size, s != st->layout.nb_streams-1, !vbr && s == st->layout.nb_streams-1);
data += len;
diff --git a/src/repacketizer.c b/src/repacketizer.c
index f27e9ab9..c80ee7f0 100644
--- a/src/repacketizer.c
+++ b/src/repacketizer.c
@@ -249,7 +249,9 @@ int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len)
opus_repacketizer_init(&rp);
/* Moving payload to the end of the packet so we can do in-place padding */
OPUS_MOVE(data+new_len-len, data, len);
- opus_repacketizer_cat(&rp, data+new_len-len, len);
+ ret = opus_repacketizer_cat(&rp, data+new_len-len, len);
+ if (ret != OPUS_OK)
+ return ret;
ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, new_len, 0, 1);
if (ret > 0)
return OPUS_OK;
diff --git a/tests/test_opus_api.c b/tests/test_opus_api.c
index 9bfa5cca..489052d2 100644
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -1699,9 +1699,9 @@ int test_repacketizer_api(void)
cfgs++;
if(opus_multistream_packet_pad(po,4,4,1)!=OPUS_OK)test_failed();
cfgs++;
- if(opus_packet_pad(po,4,5)!=OPUS_BAD_ARG)test_failed();
+ if(opus_packet_pad(po,4,5)!=OPUS_INVALID_PACKET)test_failed();
cfgs++;
- if(opus_multistream_packet_pad(po,4,5,1)!=OPUS_BAD_ARG)test_failed();
+ if(opus_multistream_packet_pad(po,4,5,1)!=OPUS_INVALID_PACKET)test_failed();
cfgs++;
if(opus_packet_pad(po,0,5)!=OPUS_BAD_ARG)test_failed();
cfgs++;