Merge commit '30db94dc399f6e4ef8905049d9b740556f0fce47'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 29 Sep 2013 23:09:38 +0000 (01:09 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 29 Sep 2013 23:12:15 +0000 (01:12 +0200)
* commit '30db94dc399f6e4ef8905049d9b740556f0fce47':
  xan: Use bytestream2 to limit reading to within the buffer

Conflicts:
libavcodec/xan.c

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

@@@ -293,17 -280,16 +293,16 @@@ static int xan_wc3_decode_frame(XanCont
      int motion_x, motion_y;
      int x, y;
  
 -    unsigned char *opcode_buffer = s->buffer1;
 -    unsigned char *opcode_buffer_end = s->buffer1 + s->buffer1_size;
 +    uint8_t *opcode_buffer = s->buffer1;
 +    uint8_t *opcode_buffer_end = s->buffer1 + s->buffer1_size;
      int opcode_buffer_size = s->buffer1_size;
 -    const unsigned char *imagedata_buffer = s->buffer2;
 +    const uint8_t *imagedata_buffer = s->buffer2;
  
      /* pointers to segments inside the compressed chunk */
 -    const unsigned char *huffman_segment;
 +    const uint8_t *huffman_segment;
-     const uint8_t *size_segment;
-     const uint8_t *vector_segment;
+     GetByteContext       size_segment;
+     GetByteContext       vector_segment;
 -    const unsigned char *imagedata_segment;
 +    const uint8_t *imagedata_segment;
-     const uint8_t *buf_end = s->buf + s->size;
      int huffman_offset, size_offset, vector_offset, imagedata_offset,
          imagedata_size;
  
  
          case 9:
          case 19:
-             if (buf_end - size_segment < 1) {
++            if (bytestream2_get_bytes_left(&size_segment) < 1) {
 +                av_log(s->avctx, AV_LOG_ERROR, "size_segment overread\n");
 +                return AVERROR_INVALIDDATA;
 +            }
-             size = *size_segment++;
+             size = bytestream2_get_byte(&size_segment);
              break;
  
          case 10:
          case 20:
-             if (buf_end - size_segment < 2) {
++            if (bytestream2_get_bytes_left(&size_segment) < 2) {
 +                av_log(s->avctx, AV_LOG_ERROR, "size_segment overread\n");
 +                return AVERROR_INVALIDDATA;
 +            }
-             size = AV_RB16(&size_segment[0]);
-             size_segment += 2;
+             size = bytestream2_get_be16(&size_segment);
              break;
  
          case 11:
          case 21:
-             if (buf_end - size_segment < 3) {
++            if (bytestream2_get_bytes_left(&size_segment) < 3) {
 +                av_log(s->avctx, AV_LOG_ERROR, "size_segment overread\n");
 +                return AVERROR_INVALIDDATA;
 +            }
-             size = AV_RB24(size_segment);
-             size_segment += 3;
+             size = bytestream2_get_be24(&size_segment);
              break;
          }
  
                  imagedata_size -= size;
              }
          } else {
-             if (vector_segment >= buf_end) {
++            uint8_t vector;
++            if (bytestream2_get_bytes_left(&vector_segment) <= 0) {
 +                av_log(s->avctx, AV_LOG_ERROR, "vector_segment overread\n");
 +                return AVERROR_INVALIDDATA;
 +            }
              /* run-based motion compensation from last frame */
-             motion_x = sign_extend(*vector_segment >> 4,  4);
-             motion_y = sign_extend(*vector_segment & 0xF, 4);
-             vector_segment++;
 -            uint8_t vector = bytestream2_get_byte(&vector_segment);
++            vector = bytestream2_get_byte(&vector_segment);
+             motion_x = sign_extend(vector >> 4,  4);
+             motion_y = sign_extend(vector & 0xF, 4);
  
              /* copy a run of pixels from the previous frame */
              xan_wc3_copy_pixel_run(s, frame, x, y, size, motion_x, motion_y);