From: Richard Mudgett Date: Wed, 25 Oct 2017 19:38:19 +0000 (-0500) Subject: codec.c: Defensively check the returned samples. X-Git-Tag: 13.19.0-rc1~184^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca7f3d297b53785ba3b5282a569ea8add9717c8b;p=thirdparty%2Fasterisk.git codec.c: Defensively check the returned samples. Earlier versions of the codec_opus samples_count callback can return negative error values on undecodable frames. This resulted in a divide by zero exception. * Added a defensive check in ast_codec_samples_count() for a "negative" samples count return value. Log the event and set the count to zero. ASTERISK-27194 Change-Id: Icf69350307ecbbc80a3d74de46af9bd80ea17819 --- diff --git a/main/codec.c b/main/codec.c index c253233bb6..d0e63682b8 100644 --- a/main/codec.c +++ b/main/codec.c @@ -393,6 +393,11 @@ unsigned int ast_codec_samples_count(struct ast_frame *frame) if (codec->samples_count) { samples = codec->samples_count(frame); + if ((int) samples < 0) { + ast_log(LOG_WARNING, "Codec %s returned invalid number of samples.\n", + ast_format_get_name(frame->subclass.format)); + samples = 0; + } } else { ast_log(LOG_WARNING, "Unable to calculate samples for codec %s\n", ast_format_get_name(frame->subclass.format));