Merge commit '1a3598aae768465a8efc8475b6df5a8261bc62fc'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 3 Jul 2013 10:54:01 +0000 (12:54 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 3 Jul 2013 10:54:01 +0000 (12:54 +0200)
* commit '1a3598aae768465a8efc8475b6df5a8261bc62fc':
  jpeg2000: Use bytestream2

Conflicts:
libavcodec/jpeg2000dec.c

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

@@@ -189,17 -173,12 +189,17 @@@ static int get_siz(Jpeg2000DecoderConte
          return AVERROR_INVALIDDATA;
  
      for (i = 0; i < s->ncomponents; i++) { // Ssiz_i XRsiz_i, YRsiz_i
-         uint8_t x = bytestream2_get_byteu(&s->g);
+         uint8_t x    = bytestream2_get_byteu(&s->g);
          s->cbps[i]   = (x & 0x7f) + 1;
          s->precision = FFMAX(s->cbps[i], s->precision);
 -        s->sgnd[i]   = (x & 0x80) == 1;
 +        s->sgnd[i]   = !!(x & 0x80);
          s->cdx[i]    = bytestream2_get_byteu(&s->g);
          s->cdy[i]    = bytestream2_get_byteu(&s->g);
 +        if (s->cdx[i] != 1 || s->cdy[i] != 1) {
 +            av_log(s->avctx, AV_LOG_ERROR, "unsupported/ CDxy values %d %d for component %d\n", s->cdx[i], s->cdy[i], i);
 +            if (!s->cdx[i] || !s->cdy[i])
 +                return AVERROR_INVALIDDATA;
 +        }
      }
  
      s->numXtiles = ff_jpeg2000_ceildiv(s->width  - s->tile_offset_x, s->tile_width);
@@@ -327,17 -306,10 +328,17 @@@ static int get_cod(Jpeg2000DecoderConte
      // get progression order
      tmp.prog_order = bytestream2_get_byteu(&s->g);
  
-     tmp.nlayers = bytestream2_get_be16u(&s->g);
-     tmp.mct     = bytestream2_get_byteu(&s->g); // multiple component transformation
+     tmp.nlayers    = bytestream2_get_be16u(&s->g);
+     tmp.mct        = bytestream2_get_byteu(&s->g); // multiple component transformation
  
 -    get_cox(s, &tmp);
 +    if (tmp.mct && s->ncomponents < 3) {
 +        av_log(s->avctx, AV_LOG_ERROR, "MCT %d with too few components (%d)\n", tmp.mct, s->ncomponents);
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    if ((ret = get_cox(s, &tmp)) < 0)
 +        return ret;
 +
      for (compno = 0; compno < s->ncomponents; compno++)
          if (!(properties[compno] & HAD_COC))
              memcpy(c + compno, &tmp, sizeof(tmp));
@@@ -386,7 -351,8 +387,8 @@@ static int get_qcx(Jpeg2000DecoderConte
  
      if (q->quantsty == JPEG2000_QSTY_NONE) {
          n -= 3;
-         if (bytestream2_get_bytes_left(&s->g) < n || 32*3 < n)
+         if (bytestream2_get_bytes_left(&s->g) < n ||
 -            n > JPEG2000_MAX_DECLEVELS)
++            n > JPEG2000_MAX_DECLEVELS*3)
              return AVERROR_INVALIDDATA;
          for (i = 0; i < n; i++)
              q->expn[i] = bytestream2_get_byteu(&s->g) >> 3;
          }
      } else {
          n = (n - 3) >> 1;
-         if (bytestream2_get_bytes_left(&s->g) < 2 * n || 32*3 < n)
+         if (bytestream2_get_bytes_left(&s->g) < 2 * n ||
 -            n > JPEG2000_MAX_DECLEVELS)
++            n > JPEG2000_MAX_DECLEVELS*3)
              return AVERROR_INVALIDDATA;
          for (i = 0; i < n; i++) {
              x          = bytestream2_get_be16u(&s->g);
@@@ -1329,7 -1232,9 +1332,9 @@@ static int jp2_find_codestream(Jpeg2000
      uint32_t atom_size, atom;
      int found_codestream = 0, search_range = 10;
  
-     while (!found_codestream && search_range && bytestream2_get_bytes_left(&s->g) >= 8) {
 -    while(!found_codestream && search_range
 -          &&
 -          bytestream2_get_bytes_left(&s->g) >= 8) {
++    while (!found_codestream && search_range
++           &&
++           bytestream2_get_bytes_left(&s->g) >= 8) {
          atom_size = bytestream2_get_be32u(&s->g);
          atom      = bytestream2_get_be32u(&s->g);
          if (atom == JP2_CODESTREAM) {