Merge commit '61cd19b8bc32185c8caf64d89d1b0909877a0707'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 10 Oct 2013 07:18:16 +0000 (09:18 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 10 Oct 2013 07:19:05 +0000 (09:19 +0200)
* commit '61cd19b8bc32185c8caf64d89d1b0909877a0707':
  vmnc: Port to bytestream2

Conflicts:
libavcodec/vmnc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/vmnc.c

@@@ -317,16 -307,19 +307,18 @@@ static int decode_frame(AVCodecContext 
      const uint8_t *buf = avpkt->data;
      int buf_size       = avpkt->size;
      VmncContext * const c = avctx->priv_data;
+     GetByteContext *gb = &c->gb;
      uint8_t *outptr;
-     const uint8_t *src = buf;
      int dx, dy, w, h, depth, enc, chunks, res, size_left, ret;
 +    AVFrame *frame = c->frame;
  
 -    if ((ret = ff_reget_buffer(avctx, &c->pic)) < 0) {
 -        av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
 +    if ((ret = ff_reget_buffer(avctx, frame)) < 0)
          return ret;
 -    }
  
 -    c->pic.key_frame = 0;
 -    c->pic.pict_type = AV_PICTURE_TYPE_P;
+     bytestream2_init(gb, buf, buf_size);
 +    frame->key_frame = 0;
 +    frame->pict_type = AV_PICTURE_TYPE_P;
  
      // restore screen after cursor
      if (c->screendta) {
              }
          }
      }
-     src += 2;
-     chunks = AV_RB16(src);
-     src += 2;
+     bytestream2_skip(gb, 2);
+     chunks = bytestream2_get_be16(gb);
      while (chunks--) {
-         if (buf_size - (src - buf) < 12) {
++        if (bytestream2_get_bytes_left(gb) < 12) {
 +            av_log(avctx, AV_LOG_ERROR, "Premature end of data!\n");
 +            return -1;
 +        }
-         dx  = AV_RB16(src);
-         src += 2;
-         dy  = AV_RB16(src);
-         src += 2;
-         w   = AV_RB16(src);
-         src += 2;
-         h   = AV_RB16(src);
-         src += 2;
-         enc = AV_RB32(src);
-         src += 4;
+         dx  = bytestream2_get_be16(gb);
+         dy  = bytestream2_get_be16(gb);
+         w   = bytestream2_get_be16(gb);
+         h   = bytestream2_get_be16(gb);
+         enc = bytestream2_get_be32(gb);
 -        outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
 +        outptr = frame->data[0] + dx * c->bpp2 + dy * frame->linesize[0];
-         size_left = buf_size - (src - buf);
+         size_left = bytestream2_get_bytes_left(gb);
          switch (enc) {
          case MAGIC_WMVd: // cursor
 +            if (w*(int64_t)h*c->bpp2 > INT_MAX/2 - 2) {
 +                av_log(avctx, AV_LOG_ERROR, "dimensions too large\n");
 +                return AVERROR_INVALIDDATA;
 +            }
              if (size_left < 2 + w * h * c->bpp2 * 2) {
                  av_log(avctx, AV_LOG_ERROR,
                         "Premature end of data! (need %i got %i)\n",
                         c->cur_hx, c->cur_hy, c->cur_w, c->cur_h);
                  c->cur_hx = c->cur_hy = 0;
              }
 -            c->curbits   = av_realloc(c->curbits,   c->cur_w * c->cur_h * c->bpp2);
 -            c->curmask   = av_realloc(c->curmask,   c->cur_w * c->cur_h * c->bpp2);
 -            c->screendta = av_realloc(c->screendta, c->cur_w * c->cur_h * c->bpp2);
 +            c->curbits   = av_realloc_f(c->curbits,   c->cur_w * c->cur_h, c->bpp2);
 +            c->curmask   = av_realloc_f(c->curmask,   c->cur_w * c->cur_h, c->bpp2);
 +            c->screendta = av_realloc_f(c->screendta, c->cur_w * c->cur_h, c->bpp2);
 +            if (!c->curbits || !c->curmask || !c->screendta)
 +                return AVERROR(ENOMEM);
-             load_cursor(c, src);
-             src += w * h * c->bpp2 * 2;
+             load_cursor(c);
              break;
          case MAGIC_WMVe: // unknown
-             src += 2;
+             bytestream2_skip(gb, 2);
              break;
          case MAGIC_WMVf: // update cursor position
              c->cur_x = dx - c->cur_hx;
              c->cur_y = dy - c->cur_hy;
              break;
          case MAGIC_WMVg: // unknown
-             src += 10;
+             bytestream2_skip(gb, 10);
              break;
          case MAGIC_WMVh: // unknown
-             src += 4;
+             bytestream2_skip(gb, 4);
              break;
          case MAGIC_WMVi: // ServerInitialization struct
 -            c->pic.key_frame = 1;
 -            c->pic.pict_type = AV_PICTURE_TYPE_I;
 +            frame->key_frame = 1;
 +            frame->pict_type = AV_PICTURE_TYPE_I;
-             depth = *src++;
+             depth = bytestream2_get_byte(gb);
              if (depth != c->bpp) {
                  av_log(avctx, AV_LOG_INFO,
                         "Depth mismatch. Container %i bpp, "
                         w * h * c->bpp2, size_left);
                  return -1;
              }
-             paint_raw(outptr, w, h, src, c->bpp2, c->bigendian,
+             paint_raw(outptr, w, h, gb, c->bpp2, c->bigendian,
 -                      c->pic.linesize[0]);
 +                      frame->linesize[0]);
-             src += w * h * c->bpp2;
              break;
          case 0x00000005: // HexTile encoded rectangle
              if ((dx + w > c->width) || (dy + h > c->height)) {
                         w, h, dx, dy, c->width, c->height);
                  return -1;
              }
-             res = decode_hextile(c, outptr, src, size_left, w, h,
-                                  frame->linesize[0]);
 -            res = decode_hextile(c, outptr, gb, w, h, c->pic.linesize[0]);
++            res = decode_hextile(c, outptr, gb, w, h, frame->linesize[0]);
              if (res < 0)
                  return -1;
-             src += res;
              break;
          default:
              av_log(avctx, AV_LOG_ERROR, "Unsupported block type 0x%08X\n", enc);