#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
+#include "libavutil/mem_internal.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "h263.h"
level = s->last_dc[component];
if (s->rv10_first_dc_coded[component]) {
diff = ff_rv_decode_dc(s, n);
- if (diff == 0xffff)
+ if (diff < 0)
return -1;
level += diff;
level = level & 0xff; /* handle wrap round */
if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
return ret;
+ if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
+ if ((s->width * s->height / 256 / 8) > get_bits_left(&s->gb))
+ return AVERROR_INVALIDDATA;
+ }
+
s->mb_width = (s->width + 15) / 16;
s->mb_height = (s->height + 15) / 16;
s->mb_num = s->mb_width * s->mb_height;