avcodec/yuv4enc: do not read past end of input in case of odd height

pull/390/head
Paul B Mahol 1 year ago
parent bfa43447fa
commit d33c630b2a
  1. 21
      libavcodec/yuv4enc.c

@ -29,10 +29,10 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
{ {
uint8_t *dst; uint8_t *dst;
const uint8_t *y, *u, *v; const uint8_t *y, *u, *v;
int i, j, ret; int ret;
ret = ff_get_encode_buffer(avctx, pkt, 6 * (avctx->width + 1 >> 1) ret = ff_get_encode_buffer(avctx, pkt, 6 * ((avctx->width + 1) / 2)
* (avctx->height + 1 >> 1), 0); * ((avctx->height + 1) / 2), 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
dst = pkt->data; dst = pkt->data;
@ -41,8 +41,8 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
u = pic->data[1]; u = pic->data[1];
v = pic->data[2]; v = pic->data[2];
for (i = 0; i < avctx->height + 1 >> 1; i++) { for (int i = 0; i < avctx->height / 2; i++) {
for (j = 0; j < avctx->width + 1 >> 1; j++) { for (int j = 0; j < (avctx->width + 1) / 2; j++) {
*dst++ = u[j] ^ 0x80; *dst++ = u[j] ^ 0x80;
*dst++ = v[j] ^ 0x80; *dst++ = v[j] ^ 0x80;
*dst++ = y[ 2 * j ]; *dst++ = y[ 2 * j ];
@ -55,6 +55,17 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
v += pic->linesize[2]; v += pic->linesize[2];
} }
if (avctx->height & 1) {
for (int j = 0; j < (avctx->width + 1) / 2; j++) {
*dst++ = u[j] ^ 0x80;
*dst++ = v[j] ^ 0x80;
*dst++ = y[2 * j ];
*dst++ = y[2 * j + 1];
*dst++ = y[2 * j ];
*dst++ = y[2 * j + 1];
}
}
*got_packet = 1; *got_packet = 1;
return 0; return 0;
} }

Loading…
Cancel
Save