diff options
author | Richard Mudgett <rmudgett@digium.com> | 2017-10-25 14:38:19 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2017-10-26 11:48:20 -0500 |
commit | 2ca3dbb197078e4381b932cc7d83ca8b6c088fd1 (patch) | |
tree | 624dd8b7cc04b548de55d0a7477d863068dc06de /main/codec.c | |
parent | 4f2717bab0a6aecc38083b22eb96e3c847fa32fc (diff) |
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
Diffstat (limited to 'main/codec.c')
-rw-r--r-- | main/codec.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/main/codec.c b/main/codec.c index 7797147a7..5b262f6a1 100644 --- a/main/codec.c +++ b/main/codec.c @@ -406,6 +406,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)); |