summaryrefslogtreecommitdiff
path: root/src/opus_decoder.c
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2018-03-23 13:04:13 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2018-03-27 15:13:26 -0400
commitbf1d4420c25b515842c78be88898004cc28a34e9 (patch)
tree558e1ad340e9e5418942cedf6879a30eb521a9a1 /src/opus_decoder.c
parent574d50cb572466f6391cee55781d7aa5900ca249 (diff)
downloadopus-bf1d4420c25b515842c78be88898004cc28a34e9.tar.gz
Adds Opus decoder state validation
Diffstat (limited to 'src/opus_decoder.c')
-rw-r--r--src/opus_decoder.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index 1224949f..02a88dc8 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -78,6 +78,26 @@ struct OpusDecoder {
opus_uint32 rangeFinal;
};
+#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS)
+static void validate_opus_decoder(OpusDecoder *st)
+{
+ celt_assert(st->channels == 1 || st->channels == 2);
+ celt_assert(st->Fs == 48000 || st->Fs == 24000 || st->Fs == 16000 || st->Fs == 12000 || st->Fs == 8000);
+ celt_assert(st->DecControl.API_sampleRate == st->Fs);
+ celt_assert(st->DecControl.internalSampleRate == 0 || st->DecControl.internalSampleRate == 16000 || st->DecControl.internalSampleRate == 12000 || st->DecControl.internalSampleRate == 8000);
+ celt_assert(st->DecControl.nChannelsAPI == st->channels);
+ celt_assert(st->DecControl.nChannelsInternal == 0 || st->DecControl.nChannelsInternal == 1 || st->DecControl.nChannelsInternal == 2);
+ celt_assert(st->DecControl.payloadSize_ms == 0 || st->DecControl.payloadSize_ms == 10 || st->DecControl.payloadSize_ms == 20 || st->DecControl.payloadSize_ms == 40 || st->DecControl.payloadSize_ms == 60);
+#ifdef OPUS_ARCHMASK
+ celt_assert(st->arch >= 0);
+ celt_assert(st->arch <= OPUS_ARCHMASK);
+#endif
+ celt_assert(st->stream_channels == 1 || st->stream_channels == 2);
+}
+#define VALIDATE_OPUS_DECODER(st) validate_opus_decoder(st)
+#else
+#define VALIDATE_OPUS_DECODER(st)
+#endif
int opus_decoder_get_size(int channels)
{
@@ -613,6 +633,7 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
int packet_frame_size, packet_bandwidth, packet_mode, packet_stream_channels;
/* 48 x 2.5 ms = 120 ms */
opus_int16 size[48];
+ VALIDATE_OPUS_DECODER(st);
if (decode_fec<0 || decode_fec>1)
return OPUS_BAD_ARG;
/* For FEC/PLC, frame_size has to be to have a multiple of 2.5 ms */