]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '59c6509d9f0236acbc317198eab76dab8320bced'
authorClément Bœsch <clement@stupeflix.com>
Wed, 29 Jun 2016 09:42:42 +0000 (11:42 +0200)
committerClément Bœsch <clement@stupeflix.com>
Wed, 29 Jun 2016 09:42:42 +0000 (11:42 +0200)
* commit '59c6509d9f0236acbc317198eab76dab8320bced':
  mss2: Drop a silly assert

Merged-by: Clément Bœsch <clement@stupeflix.com>
1  2 
libavcodec/mss2.c

diff --combined libavcodec/mss2.c
index d255dd4337a7d17c7bb039942f124b1825eb6308,866ce478dd56d0dbb4adef86c82896f19f875381..1e24568128bc6ed73cc8e15d3c238e8ea3ff55f8
@@@ -1,20 -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 +52,13 @@@ static void arith2_normalise(ArithCode
              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 +131,7 @@@ static int arith2_get_prob(ArithCoder *
      return i;
  }
  
 -ARITH_GET_MODEL_SYM(2)
 +ARITH_GET_MODEL_SYM(arith2)
  
  static int arith2_get_consumed_bytes(ArithCoder *c)
  {
@@@ -210,13 -210,8 +210,13 @@@ static int decode_555(GetByteContext *g
                      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(NULL, 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;
@@@ -323,7 -318,7 +323,7 @@@ static int decode_rle(GetBitContext *gb
      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 */
@@@ -386,8 -381,7 +386,8 @@@ static int decode_wmv9(AVCodecContext *
  
      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;
  
  
      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");
@@@ -482,11 -476,7 +482,8 @@@ static int mss2_decode_frame(AVCodecCon
      Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;
      int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask);
  
-     av_assert0(AV_INPUT_BUFFER_PADDING_SIZE >=
-                ARITH2_PADDING + (MIN_CACHE_BITS + 7) / 8);
 -    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);
      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]);
              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;
  
                  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,
@@@ -823,11 -816,10 +820,11 @@@ static av_cold int mss2_decode_init(AVC
      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);
      }
      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;
  }