We clip the value to prevent data type overflows and undefined behavior.
Using larger values is insanely slow anyway.
---
 libavcodec/g722enc.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 1e6fe87..4625ab9 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -80,6 +80,17 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
         avctx->frame_size = 320;
     }
 
+    if (avctx->trellis) {
+        /* validate trellis */
+        if (avctx->trellis < 0 || avctx->trellis > 16) {
+            int new_trellis = av_clip(avctx->trellis, 0, 16);
+            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;
 }
 
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to