aboutsummaryrefslogtreecommitdiff
path: root/src/opus_decoder.c
diff options
context:
space:
mode:
authorTimothy B. Terriberry <tterribe@xiph.org>2012-09-07 06:01:53 -0700
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-09-08 02:17:53 -0400
commita40689e6efccb13065a0e2db22c06208482dea6f (patch)
treed363df43e866bcf1059f05a6d4e05a34e12ab63a /src/opus_decoder.c
parent84dd1cf9b701d45124770b795656a98aa53222dd (diff)
downloadlibopus-a40689e6efccb13065a0e2db22c06208482dea6f.tar.gz
Remove large multistream stack buffers.
This avoids allocating any buffers on the stack that depend on the total channel count. Such buffers could easily exceed the size of the NONTHREADSAFE_PSEUDOSTACK. It also checks the frame_size argument in both the encoder and decoder to avoid allocating large stack buffers for opus_encode() calls that would fail anyway or opus_decode() calls that would never use all that space anyway.
Diffstat (limited to 'src/opus_decoder.c')
-rw-r--r--src/opus_decoder.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index 966ca872..161bd026 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -228,6 +228,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
RESTORE_STACK;
return OPUS_BUFFER_TOO_SMALL;
}
+ /* Limit frame_size to avoid excessive stack allocations. */
+ frame_size = IMIN(frame_size, st->Fs/25*3);
/* Payloads of 1 (2 including ToC) or 0 trigger the PLC/DTX */
if (len<=1)
{
@@ -856,6 +858,17 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...)
st->frame_size = st->Fs/400;
}
break;
+ case OPUS_GET_SAMPLE_RATE_REQUEST:
+ {
+ opus_int32 *value = va_arg(ap, opus_int32*);
+ if (value==NULL)
+ {
+ ret = OPUS_BAD_ARG;
+ break;
+ }
+ *value = st->Fs;
+ }
+ break;
case OPUS_GET_PITCH_REQUEST:
{
opus_int32 *value = va_arg(ap, opus_int32*);