Fix crash in AudrenAudioRenderer when sometime decode_and_play_sample call with NULL data and zero lenght

This commit is contained in:
rock88 2021-02-06 18:13:02 +03:00
parent 34a0ef8332
commit fba49bf66d

View file

@ -124,10 +124,13 @@ void AudrenAudioRenderer::cleanup() {
void AudrenAudioRenderer::decode_and_play_sample(char *data, int length) { void AudrenAudioRenderer::decode_and_play_sample(char *data, int length) {
if (m_decoder && m_decoded_buffer) { if (m_decoder && m_decoded_buffer) {
if (data != NULL && length > 0) {
int decoded_samples = opus_multistream_decode(m_decoder, (const unsigned char *)data, length, m_decoded_buffer, m_samples_per_frame, 0); int decoded_samples = opus_multistream_decode(m_decoder, (const unsigned char *)data, length, m_decoded_buffer, m_samples_per_frame, 0);
if (decoded_samples > 0) { if (decoded_samples > 0) {
write_audio(m_decoded_buffer, decoded_samples * m_channel_count * sizeof(s16)); write_audio(m_decoded_buffer, decoded_samples * m_channel_count * sizeof(s16));
} }
}
} else { } else {
Logger::fatal("Audren", "Invalid call of decode_and_play_sample"); Logger::fatal("Audren", "Invalid call of decode_and_play_sample");
} }