Skip to content

Commit 737ede4

Browse files
cosminphilipl
authored andcommitted
avfilter/bwdif: account for chroma sub-sampling in min size calculation
The current logic for detecting frames that are too small for the algorithm does not account for chroma sub-sampling, and so a sample where the luma plane is large enough, but the chroma planes are not will not be rejected. In that event, a heap overflow will occur. This change adjusts the logic to consider the chroma planes and makes the change to all three bwdif implementations. Fixes #10688 Signed-off-by: Cosmin Stejerean <cosmin@cosmin.at> Reviewed-by: Thomas Mundt <tmundt75@gmail.com> Signed-off-by: Philip Langdale <philipl@overt.org>
1 parent 8bdb663 commit 737ede4

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

libavfilter/vf_bwdif.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ static int config_props(AVFilterLink *link)
191191
return ret;
192192
}
193193

194-
if (link->w < 3 || link->h < 4) {
195-
av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or 4 lines is not supported\n");
194+
yadif->csp = av_pix_fmt_desc_get(link->format);
195+
yadif->filter = filter;
196+
197+
if (AV_CEIL_RSHIFT(link->w, yadif->csp->log2_chroma_w) < 3 || AV_CEIL_RSHIFT(link->h, yadif->csp->log2_chroma_h) < 4) {
198+
av_log(ctx, AV_LOG_ERROR, "Video with planes less than 3 columns or 4 lines is not supported\n");
196199
return AVERROR(EINVAL);
197200
}
198201

199-
yadif->csp = av_pix_fmt_desc_get(link->format);
200-
yadif->filter = filter;
201202
ff_bwdif_init_filter_line(&s->dsp, yadif->csp->comp[0].depth);
202203

203204
return 0;

libavfilter/vf_bwdif_cuda.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,16 @@ static int config_output(AVFilterLink *link)
296296
link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
297297
(AVRational){2, 1});
298298

299-
if (link->w < 3 || link->h < 3) {
300-
av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
301-
ret = AVERROR(EINVAL);
302-
goto exit;
303-
}
304299

305300
y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
306301
y->filter = filter;
307302

303+
if (AV_CEIL_RSHIFT(link->w, y->csp->log2_chroma_w) < 3 || AV_CEIL_RSHIFT(link->h, y->csp->log2_chroma_h) < 3) {
304+
av_log(ctx, AV_LOG_ERROR, "Video with planes less than 3 columns or lines is not supported\n");
305+
ret = AVERROR(EINVAL);
306+
goto exit;
307+
}
308+
308309
ret = CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
309310
if (ret < 0)
310311
goto exit;

libavfilter/vf_bwdif_vulkan.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,14 @@ static int bwdif_vulkan_config_output(AVFilterLink *outlink)
362362
outlink->frame_rate = av_mul_q(avctx->inputs[0]->frame_rate,
363363
(AVRational){2, 1});
364364

365-
if (outlink->w < 4 || outlink->h < 4) {
366-
av_log(avctx, AV_LOG_ERROR, "Video of less than 4 columns or lines is not "
367-
"supported\n");
368-
return AVERROR(EINVAL);
369-
}
370-
371365
y->csp = av_pix_fmt_desc_get(vkctx->frames->sw_format);
372366
y->filter = bwdif_vulkan_filter_frame;
373367

368+
if (AV_CEIL_RSHIFT(outlink->w, y->csp->log2_chroma_w) < 4 || AV_CEIL_RSHIFT(outlink->h, y->csp->log2_chroma_h) < 4) {
369+
av_log(avctx, AV_LOG_ERROR, "Video with planes less than 4 columns or lines is not supported\n");
370+
return AVERROR(EINVAL);
371+
}
372+
374373
return init_filter(avctx);
375374
}
376375

0 commit comments

Comments
 (0)