diff options
Diffstat (limited to 'libavcodec/mss2.c')
-rw-r--r-- | libavcodec/mss2.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c index 6fcadb16c9..2eb366ee78 100644 --- a/libavcodec/mss2.c +++ b/libavcodec/mss2.c @@ -1,20 +1,20 @@ /* * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -52,13 +52,13 @@ static void arith2_normalise(ArithCoder *c) c->value ^= 0x8000; c->low ^= 0x8000; } - c->high = c->high << 8 & 0xFFFFFF | 0xFF; - c->value = c->value << 8 & 0xFFFFFF | bytestream2_get_byte(c->gbc.gB); - c->low = c->low << 8 & 0xFFFFFF; + c->high = (uint16_t)c->high << 8 | 0xFF; + c->value = (uint16_t)c->value << 8 | bytestream2_get_byte(c->gbc.gB); + c->low = (uint16_t)c->low << 8; } } -ARITH_GET_BIT(2) +ARITH_GET_BIT(arith2) /* L. Stuiver and A. Moffat: "Piecewise Integer Mapping for Arithmetic Coding." * In Proc. 8th Data Compression Conference (DCC '98), pp. 3-12, Mar. 1998 */ @@ -131,7 +131,7 @@ static int arith2_get_prob(ArithCoder *c, int16_t *probs) return i; } -ARITH_GET_MODEL_SYM(2) +ARITH_GET_MODEL_SYM(arith2) static int arith2_get_consumed_bytes(ArithCoder *c) { @@ -174,7 +174,7 @@ static int decode_pal_v2(MSS12Context *ctx, const uint8_t *buf, int buf_size) return 1 + ncol * 3; } -static int decode_555(GetByteContext *gB, uint16_t *dst, ptrdiff_t stride, +static int decode_555(AVCodecContext *avctx, GetByteContext *gB, uint16_t *dst, ptrdiff_t stride, int keyframe, int w, int h) { int last_symbol = 0, repeat = 0, prev_avail = 0; @@ -210,8 +210,13 @@ static int decode_555(GetByteContext *gB, uint16_t *dst, ptrdiff_t stride, last_symbol = b << 8 | bytestream2_get_byte(gB); else if (b > 129) { repeat = 0; - while (b-- > 130) + while (b-- > 130) { + if (repeat >= (INT_MAX >> 8) - 1) { + av_log(avctx, AV_LOG_ERROR, "repeat overflow\n"); + return AVERROR_INVALIDDATA; + } repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1; + } if (last_symbol == -2) { int skip = FFMIN((unsigned)repeat, dst + w - p); repeat -= skip; @@ -318,7 +323,7 @@ static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, ptrdiff_t pal_stride, if (next_code != 1 << current_length) return AVERROR_INVALIDDATA; - if (i = init_vlc(&vlc, 9, alphabet_size, bits, 1, 1, codes, 4, 4, 0)) + if ((i = init_vlc(&vlc, 9, alphabet_size, bits, 1, 1, codes, 4, 4, 0)) < 0) return i; /* frame decode */ @@ -381,7 +386,8 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, ff_mpeg_flush(avctx); - init_get_bits(&s->gb, buf, buf_size * 8); + if ((ret = init_get_bits8(&s->gb, buf, buf_size)) < 0) + return ret; s->loop_filter = avctx->skip_loop_filter < AVDISCARD_ALL; @@ -430,8 +436,8 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, if (v->respic == 3) { ctx->dsp.upsample_plane(f->data[0], f->linesize[0], w, h); - ctx->dsp.upsample_plane(f->data[1], f->linesize[1], w >> 1, h >> 1); - ctx->dsp.upsample_plane(f->data[2], f->linesize[2], w >> 1, h >> 1); + ctx->dsp.upsample_plane(f->data[1], f->linesize[1], w+1 >> 1, h+1 >> 1); + ctx->dsp.upsample_plane(f->data[2], f->linesize[2], w+1 >> 1, h+1 >> 1); } else if (v->respic) avpriv_request_sample(v->s.avctx, "Asymmetric WMV9 rectangle subsampling"); @@ -458,9 +464,9 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, return 0; } -typedef struct Rectangle { +struct Rectangle { int coded, x, y, w, h; -} Rectangle; +}; #define MAX_WMV9_RECTANGLES 20 #define ARITH2_PADDING 2 @@ -479,10 +485,11 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, int keyframe, has_wmv9, has_mv, is_rle, is_555, ret; - Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r; + struct Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r; int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask); - init_get_bits(&gb, buf, buf_size * 8); + if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0) + return ret; if (keyframe = get_bits1(&gb)) skip_bits(&gb, 7); @@ -598,10 +605,8 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (c->mvX < 0 || c->mvY < 0) { FFSWAP(uint8_t *, c->pal_pic, c->last_pal_pic); - if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) return ret; - } if (ctx->last_pic->data[0]) { av_assert0(frame->linesize[0] == ctx->last_pic->linesize[0]); @@ -612,10 +617,8 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, return AVERROR_INVALIDDATA; } } else { - if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0) { - av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0) return ret; - } if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0) return ret; @@ -631,7 +634,7 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (is_555) { bytestream2_init(&gB, buf, buf_size); - if (decode_555(&gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1, + if (decode_555(avctx, &gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1, keyframe, avctx->width, avctx->height)) return AVERROR_INVALIDDATA; @@ -644,7 +647,8 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, ff_mss12_slicecontext_reset(&ctx->sc[1]); } if (is_rle) { - init_get_bits(&gb, buf, buf_size * 8); + if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0) + return ret; if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride, c->rgb_pic, c->rgb_stride, c->pal, keyframe, ctx->split_position, 0, @@ -822,10 +826,11 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx) c->avctx = avctx; if (ret = ff_mss12_decode_init(c, 1, &ctx->sc[0], &ctx->sc[1])) return ret; + ctx->last_pic = av_frame_alloc(); c->pal_stride = c->mask_stride; c->pal_pic = av_mallocz(c->pal_stride * avctx->height); c->last_pal_pic = av_mallocz(c->pal_stride * avctx->height); - if (!c->pal_pic || !c->last_pal_pic) { + if (!c->pal_pic || !c->last_pal_pic || !ctx->last_pic) { mss2_decode_end(avctx); return AVERROR(ENOMEM); } @@ -839,11 +844,6 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx) avctx->pix_fmt = c->free_colours == 127 ? AV_PIX_FMT_RGB555 : AV_PIX_FMT_RGB24; - ctx->last_pic = av_frame_alloc(); - if (!ctx->last_pic) { - mss2_decode_end(avctx); - return AVERROR(ENOMEM); - } return 0; } |