lavc/4xm: use bytestream2_get_bytes_left

Also replace relevant bytestream2 functions with unchecked variants due
code that already checks for overreads.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2012-12-18 18:16:36 +00:00
parent 6b50df6b3a
commit 44fe118e0a

View File

@ -346,11 +346,11 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src,
av_assert2(code >= 0 && code <= 6); av_assert2(code >= 0 && code <= 6);
if (code == 0) { if (code == 0) {
if (f->g.buffer_end - f->g.buffer < 1) { if (bytestream2_get_bytes_left(&f->g) < 1) {
av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n"); av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n");
return; return;
} }
src += f->mv[bytestream2_get_byte(&f->g)]; src += f->mv[bytestream2_get_byteu(&f->g)];
if (start > src || src > end) { if (start > src || src > end) {
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
return; return;
@ -369,37 +369,37 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src,
} else if (code == 3 && f->version < 2) { } else if (code == 3 && f->version < 2) {
mcdc(dst, src, log2w, h, stride, 1, 0); mcdc(dst, src, log2w, h, stride, 1, 0);
} else if (code == 4) { } else if (code == 4) {
if (f->g.buffer_end - f->g.buffer < 1) { if (bytestream2_get_bytes_left(&f->g) < 1) {
av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n"); av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n");
return; return;
} }
src += f->mv[bytestream2_get_byte(&f->g)]; src += f->mv[bytestream2_get_byteu(&f->g)];
if (start > src || src > end) { if (start > src || src > end) {
av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n");
return; return;
} }
if (f->g2.buffer_end - f->g2.buffer < 1){ if (bytestream2_get_bytes_left(&f->g) < 2){
av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
return; return;
} }
mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16(&f->g2)); mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16u(&f->g2));
} else if (code == 5) { } else if (code == 5) {
if (f->g2.buffer_end - f->g2.buffer < 1) { if (bytestream2_get_bytes_left(&f->g) < 2) {
av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
return; return;
} }
mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16(&f->g2)); mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16u(&f->g2));
} else if (code == 6) { } else if (code == 6) {
if (f->g2.buffer_end - f->g2.buffer < 2) { if (bytestream2_get_bytes_left(&f->g) < 4) {
av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n");
return; return;
} }
if (log2w) { if (log2w) {
dst[0] = bytestream2_get_le16(&f->g2); dst[0] = bytestream2_get_le16u(&f->g2);
dst[1] = bytestream2_get_le16(&f->g2); dst[1] = bytestream2_get_le16u(&f->g2);
} else { } else {
dst[0] = bytestream2_get_le16(&f->g2); dst[0] = bytestream2_get_le16u(&f->g2);
dst[stride] = bytestream2_get_le16(&f->g2); dst[stride] = bytestream2_get_le16u(&f->g2);
} }
} }
} }