mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/yuv4enc: do not read past end of input in case of odd height
This commit is contained in:
parent
bfa43447fa
commit
d33c630b2a
|
@ -29,10 +29,10 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||
{
|
||||
uint8_t *dst;
|
||||
const uint8_t *y, *u, *v;
|
||||
int i, j, ret;
|
||||
int ret;
|
||||
|
||||
ret = ff_get_encode_buffer(avctx, pkt, 6 * (avctx->width + 1 >> 1)
|
||||
* (avctx->height + 1 >> 1), 0);
|
||||
ret = ff_get_encode_buffer(avctx, pkt, 6 * ((avctx->width + 1) / 2)
|
||||
* ((avctx->height + 1) / 2), 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
dst = pkt->data;
|
||||
|
@ -41,8 +41,8 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||
u = pic->data[1];
|
||||
v = pic->data[2];
|
||||
|
||||
for (i = 0; i < avctx->height + 1 >> 1; i++) {
|
||||
for (j = 0; j < avctx->width + 1 >> 1; j++) {
|
||||
for (int i = 0; i < avctx->height / 2; i++) {
|
||||
for (int j = 0; j < (avctx->width + 1) / 2; j++) {
|
||||
*dst++ = u[j] ^ 0x80;
|
||||
*dst++ = v[j] ^ 0x80;
|
||||
*dst++ = y[ 2 * j ];
|
||||
|
@ -55,6 +55,17 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||
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;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue