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.
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c
index 9a7ea95..389a847 100644
--- 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;