lavfi/drawutils: ensure we don't allow mixed-byte-depth formats

These could be hazardous because of FFDrawColor's union
pull/385/head
rcombs 3 years ago
parent e24b71add5
commit f00079b25c
  1. 7
      libavfilter/drawutils.c

@ -83,6 +83,7 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
unsigned i, nb_planes = 0; unsigned i, nb_planes = 0;
int pixelstep[MAX_PLANES] = { 0 }; int pixelstep[MAX_PLANES] = { 0 };
int full_range = 0; int full_range = 0;
int depthb = 0;
if (!desc || !desc->name) if (!desc || !desc->name)
return AVERROR(EINVAL); 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) format == AV_PIX_FMT_YUVJ411P || format == AV_PIX_FMT_YUVJ440P)
full_range = 1; full_range = 1;
for (i = 0; i < desc->nb_components; i++) { for (i = 0; i < desc->nb_components; i++) {
int db;
c = &desc->comp[i]; c = &desc->comp[i];
/* for now, only 8-16 bits formats */ /* for now, only 8-16 bits formats */
if (c->depth < 8 || c->depth > 16) 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 */ /* data must either be in the high or low bits, never middle */
if (c->shift && ((c->shift + c->depth) & 0x7)) if (c->shift && ((c->shift + c->depth) & 0x7))
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
/* mixed >8 and <=8 depth */
db = (c->depth + 7) / 8;
if (depthb && (depthb != db))
return AVERROR(ENOSYS);
depthb = db;
/* strange interleaving */ /* strange interleaving */
if (pixelstep[c->plane] != 0 && if (pixelstep[c->plane] != 0 &&
pixelstep[c->plane] != c->step) pixelstep[c->plane] != c->step)

Loading…
Cancel
Save