[Asterisk-code-review] codec.c: Defensively check the returned samples. (asterisk[13])

Richard Mudgett asteriskteam at digium.com
Thu Oct 26 11:29:00 CDT 2017


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/6921


Change subject: codec.c: Defensively check the returned samples.
......................................................................

codec.c: Defensively check the returned samples.

Earlier versions of the codec_opus samples_count callback can return
negative 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
---
M main/codec.c
1 file changed, 5 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/6921/1

diff --git a/main/codec.c b/main/codec.c
index c253233..d0e6368 100644
--- a/main/codec.c
+++ b/main/codec.c
@@ -393,6 +393,11 @@
 
 	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));

-- 
To view, visit https://gerrit.asterisk.org/6921
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf69350307ecbbc80a3d74de46af9bd80ea17819
Gerrit-Change-Number: 6921
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171026/d8c201f7/attachment.html>


More information about the asterisk-code-review mailing list