#define BITSTREAM_READER_LE
+#include "libavutil/mem_internal.h"
+
#include "avcodec.h"
#include "bytestream.h"
#include "copy_block.h"
int map = s->map[x];
if (orig_mv_x >= -32) {
- if (y * 8 + mv_y < 0 || y * 8 + mv_y >= h ||
- x * 8 + mv_x < 0 || x * 8 + mv_x >= w)
+ if (y * 8 + mv_y < 0 || y * 8 + mv_y + 8 > h ||
+ x * 8 + mv_x < 0 || x * 8 + mv_x + 8 > w)
return AVERROR_INVALIDDATA;
copy_block8(frame->data[plane] + (s->blocks_h - 1 - y) * 8 * frame->linesize[plane] + x * 8,
return ret;
if (orig_mv_x >= -32) {
- if (y * 8 + mv_y < 0 || y * 8 + mv_y >= h ||
- x * 8 + mv_x < 0 || x * 8 + mv_x >= w)
+ if (y * 8 + mv_y < 0 || y * 8 + mv_y + 8 > h ||
+ x * 8 + mv_x < 0 || x * 8 + mv_x + 8 > w)
return AVERROR_INVALIDDATA;
copy_block8(frame->data[plane] + (s->blocks_h - 1 - y) * 8 * frame->linesize[plane] + x * 8,
uint8_t *dst = frame->data[0] + (avctx->height - 1) * frame->linesize[0];
uint8_t r = 0, g = 0, b = 0;
+ if (bytestream2_get_bytes_left(gbyte) < 3 * avctx->width * avctx->height)
+ return AVERROR_INVALIDDATA;
+
for (int y = 0; y < avctx->height; y++) {
for (int x = 0; x < avctx->width; x++) {
- dst[x*3+0] = bytestream2_get_byte(gbyte) + r;
+ dst[x*3+0] = bytestream2_get_byteu(gbyte) + r;
r = dst[x*3+0];
- dst[x*3+1] = bytestream2_get_byte(gbyte) + g;
+ dst[x*3+1] = bytestream2_get_byteu(gbyte) + g;
g = dst[x*3+1];
- dst[x*3+2] = bytestream2_get_byte(gbyte) + b;
+ dst[x*3+2] = bytestream2_get_byteu(gbyte) + b;
b = dst[x*3+2];
}
dst -= frame->linesize[0];
return 0;
}
-static int fill_pixels(uint8_t **y0, uint8_t **y1,
+av_always_inline static int fill_pixels(uint8_t **y0, uint8_t **y1,
uint8_t **u, uint8_t **v,
int ylinesize, int ulinesize, int vlinesize,
uint8_t *fill,
static int decode_motion_vectors(AVCodecContext *avctx, GetBitContext *gb)
{
AGMContext *s = avctx->priv_data;
- int nb_mvs = ((avctx->height + 15) >> 4) * ((avctx->width + 15) >> 4);
+ int nb_mvs = ((avctx->coded_height + 15) >> 4) * ((avctx->coded_width + 15) >> 4);
int ret, skip = 0, value, map;
av_fast_padded_malloc(&s->mvectors, &s->mvectors_size,
codes[idx] = pfx;
} else if (idx >= 0) {
get_tree_codes(codes, nodes, nodes[idx].child[0], pfx + (0 << bitpos), bitpos + 1);
- get_tree_codes(codes, nodes, nodes[idx].child[1], pfx + (1 << bitpos), bitpos + 1);
+ get_tree_codes(codes, nodes, nodes[idx].child[1], pfx + (1U << bitpos), bitpos + 1);
}
}
frame->key_frame = s->key_frame;
frame->pict_type = s->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+ if (!s->key_frame) {
+ if (!s->prev_frame->data[0]) {
+ av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
if (header) {
if (avctx->codec_tag == MKTAG('A', 'G', 'M', '0') ||
avctx->codec_tag == MKTAG('A', 'G', 'M', '1'))
else
ret = decode_intra(avctx, gb, frame);
} else {
- if (!s->prev_frame->data[0]) {
- av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
- return AVERROR_INVALIDDATA;
- }
if (s->prev_frame-> width != frame->width ||
s->prev_frame->height != frame->height)
return AVERROR_INVALIDDATA;
s->dct = avctx->codec_tag != MKTAG('A', 'G', 'M', '4') &&
avctx->codec_tag != MKTAG('A', 'G', 'M', '5');
+ if (!s->rgb && !s->dct) {
+ if ((avctx->width & 1) || (avctx->height & 1))
+ return AVERROR_INVALIDDATA;
+ }
+
avctx->idct_algo = FF_IDCT_SIMPLE;
ff_idctdsp_init(&s->idsp, avctx);
ff_init_scantable(s->idsp.idct_permutation, &s->scantable, ff_zigzag_direct);
return 0;
}
-AVCodec ff_agm_decoder = {
+const AVCodec ff_agm_decoder = {
.name = "agm",
.long_name = NULL_IF_CONFIG_SMALL("Amuse Graphics Movie"),
.type = AVMEDIA_TYPE_VIDEO,