Don't update the internal decoder state until we know the packet is valid
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 4 Dec 2012 19:13:00 +0000 (14:13 -0500)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 4 Dec 2012 20:16:54 +0000 (15:16 -0500)
src/opus_decoder.c

index 98de210..015ae17 100644 (file)
@@ -785,17 +785,20 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
          return frame_size;
    }
    tot_offset = 0;
-   st->mode = packet_mode;
-   st->bandwidth = packet_bandwidth;
-   st->frame_size = packet_frame_size;
-   st->stream_channels = packet_stream_channels;
    if (count < 0)
       return count;
 
    tot_offset += offset;
 
-   if (count*st->frame_size > frame_size)
+   if (count*packet_frame_size > frame_size)
       return OPUS_BUFFER_TOO_SMALL;
+
+   /* Update the state as the last step to avoid updating it on an invalid packet */
+   st->mode = packet_mode;
+   st->bandwidth = packet_bandwidth;
+   st->frame_size = packet_frame_size;
+   st->stream_channels = packet_stream_channels;
+
    nb_samples=0;
    for (i=0;i<count;i++)
    {