img_format: prevent an offset >= MP_MAX_PLANES into bpp

Addresses the warning: "writing 1 byte into a region of size 0"
This commit is contained in:
Mike Will 2024-08-07 15:59:28 -04:00 committed by sfan5
parent e3f426aa4a
commit acc69e082f
1 changed files with 2 additions and 1 deletions

View File

@ -399,7 +399,8 @@ fail:
for (int n = 0; n < 4; n++) for (int n = 0; n < 4; n++)
desc->comps[n] = (struct mp_imgfmt_comp_desc){0}; desc->comps[n] = (struct mp_imgfmt_comp_desc){0};
// Average bit size fallback. // 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++) { for (int p = 0; p < desc->num_planes; p++) {
int ls = av_image_get_linesize(fmt, 256, p); int ls = av_image_get_linesize(fmt, 256, p);
desc->bpp[p] = ls > 0 ? ls * 8 / 256 : 0; desc->bpp[p] = ls > 0 ? ls * 8 / 256 : 0;