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

Joshua Colp asteriskteam at digium.com
Fri Oct 27 09:05:53 CDT 2017


Joshua Colp has submitted this change and it was merged. ( 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 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
---
M main/codec.c
1 file changed, 5 insertions(+), 0 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



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: merged
Gerrit-Change-Id: Icf69350307ecbbc80a3d74de46af9bd80ea17819
Gerrit-Change-Number: 6921
Gerrit-PatchSet: 2
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171027/1b493c25/attachment-0001.html>


More information about the asterisk-code-review mailing list