From acc69e082fff67398834de3045ef48d33d2f4d54 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Wed, 7 Aug 2024 15:59:28 -0400 Subject: [PATCH] img_format: prevent an offset >= MP_MAX_PLANES into bpp Addresses the warning: "writing 1 byte into a region of size 0" --- video/img_format.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/video/img_format.c b/video/img_format.c index c9e2a3c0e6..20e23a9eb0 100644 --- a/video/img_format.c +++ b/video/img_format.c @@ -399,7 +399,8 @@ fail: for (int n = 0; n < 4; n++) desc->comps[n] = (struct mp_imgfmt_comp_desc){0}; // Average bit size fallback. - desc->num_planes = av_pix_fmt_count_planes(fmt); + int num_planes = av_pix_fmt_count_planes(fmt); + desc->num_planes = MPCLAMP(num_planes, 0, MP_MAX_PLANES); for (int p = 0; p < desc->num_planes; p++) { int ls = av_image_get_linesize(fmt, 256, p); desc->bpp[p] = ls > 0 ? ls * 8 / 256 : 0;