avcodec/mpegvideo_dec: Check for existence of planes before accesses

Fixes segfaults with -debug +nomc -flags +gray (presuming
a build with --enable-gray).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2023-09-30 18:07:58 +02:00
parent 8d12762b42
commit 3ede6cc0f1
1 changed files with 4 additions and 2 deletions

View File

@ -249,10 +249,12 @@ static void gray_frame(AVFrame *frame)
{ {
int h_chroma_shift, v_chroma_shift; int h_chroma_shift, v_chroma_shift;
av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift);
for (int i = 0; i < frame->height; i++) for (int i = 0; i < frame->height; i++)
memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width); memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width);
if (!frame->data[1])
return;
av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift);
for (int i = 0; i < AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) { for (int i = 0; i < AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) {
memset(frame->data[1] + frame->linesize[1] * i, memset(frame->data[1] + frame->linesize[1] * i,
0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift)); 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));