Merge commit '0aed0bfc62b273a780a2bfba3be56039fccd7423'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 3 Jun 2013 10:21:25 +0000 (12:21 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 3 Jun 2013 10:21:25 +0000 (12:21 +0200)
* commit '0aed0bfc62b273a780a2bfba3be56039fccd7423':
  vmd: fix mode 3 decoding

Conflicts:
libavcodec/vmdav.c

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

@@@ -148,13 -147,15 +148,14 @@@ static void lz_unpack(const unsigned ch
          }
      }
  }
 -
  static int rle_unpack(const unsigned char *src, unsigned char *dest,
 -    int src_count, int src_size, int dest_len)
 +                      int src_count, int src_size, int dest_len)
  {
      unsigned char *pd;
-     int i, j, l;
+     int i, l, used = 0;
      unsigned char *dest_end = dest + dest_len;
      GetByteContext gb;
+     uint16_t run_val;
  
      bytestream2_init(&gb, src, src_size);
      pd = dest;
          l = bytestream2_get_byteu(&gb);
          if (l & 0x80) {
              l = (l & 0x7F) * 2;
 -            if (pd + l > dest_end || bytestream2_get_bytes_left(&gb) < l)
 +            if (dest_end - pd < l || bytestream2_get_bytes_left(&gb) < l)
                  return bytestream2_tell(&gb);
 -            bytestream2_get_buffer(&gb, pd, l);
 +            bytestream2_get_bufferu(&gb, pd, l);
              pd += l;
          } else {
-             int ps[2];
 -            if (pd + l > dest_end || bytestream2_get_bytes_left(&gb) < 2)
 +            if (dest_end - pd < 2*l || bytestream2_get_bytes_left(&gb) < 2)
                  return bytestream2_tell(&gb);
-             ps[0] = bytestream2_get_byteu(&gb);
-             ps[1] = bytestream2_get_byteu(&gb);
-             for (j = 0; j < l; j++) {
-                 *pd++ = ps[0];
-                 *pd++ = ps[1];
+             run_val = bytestream2_get_ne16(&gb);
+             for (i = 0; i < l; i++) {
+                 AV_WN16(pd, run_val);
+                 pd += 2;
              }
+             l *= 2;
          }
-         i += l;
-     } while (i < src_count);
+         used += l;
+     } while (used < src_count);
  
      return bytestream2_tell(&gb);
  }