vmd: refactor the inner decode loop
Simplify a little, assume empty frames are acceptable and
do not pointlessly reinit the bytestream2 contexts using
possibly wrong size values.
Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
(cherry picked from commit 676da248ca
)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Conflicts:
libavcodec/vmdav.c
This commit is contained in:
@@ -269,9 +269,11 @@ static int vmd_decode(VmdVideoContext *s)
|
|||||||
}
|
}
|
||||||
s->size -= PALETTE_COUNT * 3 + 2;
|
s->size -= PALETTE_COUNT * 3 + 2;
|
||||||
}
|
}
|
||||||
if (s->size > 0) {
|
|
||||||
|
if (!s->size)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* originally UnpackFrame in VAG's code */
|
/* originally UnpackFrame in VAG's code */
|
||||||
bytestream2_init(&gb, gb.buffer, s->buf + s->size - gb.buffer);
|
|
||||||
if (bytestream2_get_bytes_left(&gb) < 1)
|
if (bytestream2_get_bytes_left(&gb) < 1)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
meth = bytestream2_get_byteu(&gb);
|
meth = bytestream2_get_byteu(&gb);
|
||||||
@@ -292,7 +294,8 @@ static int vmd_decode(VmdVideoContext *s)
|
|||||||
len = bytestream2_get_byte(&gb);
|
len = bytestream2_get_byte(&gb);
|
||||||
if (len & 0x80) {
|
if (len & 0x80) {
|
||||||
len = (len & 0x7F) + 1;
|
len = (len & 0x7F) + 1;
|
||||||
if (ofs + len > frame_width || bytestream2_get_bytes_left(&gb) < len)
|
if (ofs + len > frame_width ||
|
||||||
|
bytestream2_get_bytes_left(&gb) < len)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
bytestream2_get_buffer(&gb, &dp[ofs], len);
|
bytestream2_get_buffer(&gb, &dp[ofs], len);
|
||||||
ofs += len;
|
ofs += len;
|
||||||
@@ -305,7 +308,8 @@ static int vmd_decode(VmdVideoContext *s)
|
|||||||
}
|
}
|
||||||
} while (ofs < frame_width);
|
} while (ofs < frame_width);
|
||||||
if (ofs > frame_width) {
|
if (ofs > frame_width) {
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
|
av_log(s->avctx, AV_LOG_ERROR,
|
||||||
|
"VMD video: offset > width (%d > %d)\n",
|
||||||
ofs, frame_width);
|
ofs, frame_width);
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
@@ -345,7 +349,8 @@ static int vmd_decode(VmdVideoContext *s)
|
|||||||
}
|
}
|
||||||
} while (ofs < frame_width);
|
} while (ofs < frame_width);
|
||||||
if (ofs > frame_width) {
|
if (ofs > frame_width) {
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
|
av_log(s->avctx, AV_LOG_ERROR,
|
||||||
|
"VMD video: offset > width (%d > %d)\n",
|
||||||
ofs, frame_width);
|
ofs, frame_width);
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
@@ -354,7 +359,6 @@ static int vmd_decode(VmdVideoContext *s)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user