shithub: opus

Download patch

ref: 328953e1896432bc700b9b5c69ae2987c5d752f4
parent: f6f8487b76f234437e7d4c2831e630d9d06cb074
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Sun Jul 3 21:29:23 EDT 2016

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.

--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -968,6 +968,7 @@
       int len;
       int curr_max;
       int c1, c2;
+      int ret;
 
       opus_repacketizer_init(&rp);
       enc = (OpusEncoder*)ptr;
@@ -1027,7 +1028,11 @@
       /* 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;
--- a/src/repacketizer.c
+++ b/src/repacketizer.c
@@ -249,7 +249,9 @@
    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;
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -1699,9 +1699,9 @@
    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++;