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

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


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


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/22/6922/1

diff --git a/main/codec.c b/main/codec.c
index 7797147..5b262f6 100644
--- a/main/codec.c
+++ b/main/codec.c
@@ -406,6 +406,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/6922
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf69350307ecbbc80a3d74de46af9bd80ea17819
Gerrit-Change-Number: 6922
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/77e56cbd/attachment-0001.html>


More information about the asterisk-code-review mailing list