All elements should be within 1-255.
---
 libavcodec/encode.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 3baf5b8103..27edb00b04 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -646,6 +646,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
         avctx->sw_pix_fmt = frames_ctx->sw_format;
     }
 
+    {
+        uint16_t  *matrices[] = {avctx->intra_matrix, avctx->inter_matrix, 
avctx->chroma_intra_matrix};
+        const char   *names[] = {"Intra", "Inter", "Chroma Intra"};
+        for (int m = 0; m < FF_ARRAY_ELEMS(matrices) && m < 
FF_ARRAY_ELEMS(names); m++) {
+            uint16_t *matrix = matrices[m];
+            if (matrix) {
+                for (int i = 0; i < 64; i++) {
+                    if (matrix[i] == 0 || matrix[i] > 255) {
+                        av_log(avctx, AV_LOG_ERROR, "%s matrix[%d] is %d which 
is out of the allowed range [1-255].\n", names[m], i, matrix[i]);
+                        return AVERROR(EINVAL);
+                    }
+                }
+            }
+        }
+    }
+
     return 0;
 }
 
-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to