summaryrefslogtreecommitdiff
path: root/libavcodec/g722enc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-01-06 16:01:07 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2012-01-07 13:38:23 -0500
commitcf1a259ad6eb7ad80fce1f2c2b86fda846e401c2 (patch)
treef2c82c3799dd575965efbf8f08955f34d1858631 /libavcodec/g722enc.c
parent77c5b66cbec5a04c846b0dd3997c898146334b60 (diff)
g722enc: validate AVCodecContext.trellis
Diffstat (limited to 'libavcodec/g722enc.c')
-rw-r--r--libavcodec/g722enc.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index ceb18b46db..1cb0070649 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -36,6 +36,11 @@
problems, so we limit it to a reasonable value */
#define MAX_FRAME_SIZE 32768
+/* We clip the value of avctx->trellis to prevent data type overflows and
+ undefined behavior. Using larger values is insanely slow anyway. */
+#define MIN_TRELLIS 0
+#define MAX_TRELLIS 16
+
static av_cold int g722_encode_init(AVCodecContext * avctx)
{
G722Context *c = avctx->priv_data;
@@ -83,6 +88,17 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
avctx->frame_size = 320;
}
+ if (avctx->trellis) {
+ /* validate trellis */
+ if (avctx->trellis < MIN_TRELLIS || avctx->trellis > MAX_TRELLIS) {
+ int new_trellis = av_clip(avctx->trellis, MIN_TRELLIS, MAX_TRELLIS);
+ av_log(avctx, AV_LOG_WARNING, "Requested trellis value is not "
+ "allowed. Using %d instead of %d\n", new_trellis,
+ avctx->trellis);
+ avctx->trellis = new_trellis;
+ }
+ }
+
return 0;
}