diff mbox series

[FFmpeg-devel,12/16] lavfi/drawutils: ensure we don't allow mixed-byte-depth formats

Message ID 20211224030904.1196-13-rcombs@rcombs.me
State Accepted
Commit f00079b25c44d6b9f01bb3688bfd1cd49abefac8
Headers show
Series [FFmpeg-devel,01/16] swscale/output: template-ize yuv2nv12cX 10-bit and 16-bit cases | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc fail Make fate failed

Commit Message

rcombs Dec. 24, 2021, 3:09 a.m. UTC
These could be hazardous because of FFDrawColor's union
---
 libavfilter/drawutils.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c
index e4d6ddcf4c..99c124822d 100644
--- a/libavfilter/drawutils.c
+++ b/libavfilter/drawutils.c
@@ -83,6 +83,7 @@  int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
     unsigned i, nb_planes = 0;
     int pixelstep[MAX_PLANES] = { 0 };
     int full_range = 0;
+    int depthb = 0;
 
     if (!desc || !desc->name)
         return AVERROR(EINVAL);
@@ -96,6 +97,7 @@  int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
         format == AV_PIX_FMT_YUVJ411P || format == AV_PIX_FMT_YUVJ440P)
         full_range = 1;
     for (i = 0; i < desc->nb_components; i++) {
+        int db;
         c = &desc->comp[i];
         /* for now, only 8-16 bits formats */
         if (c->depth < 8 || c->depth > 16)
@@ -105,6 +107,11 @@  int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
         /* data must either be in the high or low bits, never middle */
         if (c->shift && ((c->shift + c->depth) & 0x7))
             return AVERROR(ENOSYS);
+        /* mixed >8 and <=8 depth */
+        db = (c->depth + 7) / 8;
+        if (depthb && (depthb != db))
+            return AVERROR(ENOSYS);
+        depthb = db;
         /* strange interleaving */
         if (pixelstep[c->plane] != 0 &&
             pixelstep[c->plane] != c->step)