Merge commit 'a2448cfe167a4cd4eb631318550d4eef38fca24a'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 13 Nov 2014 14:20:40 +0000 (15:20 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 13 Nov 2014 14:20:40 +0000 (15:20 +0100)
* commit 'a2448cfe167a4cd4eb631318550d4eef38fca24a':
  jpeg2000: do not compute the same value twice

Conflicts:
libavcodec/jpeg2000.c

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

@@@ -369,13 -373,10 +369,14 @@@ int ff_jpeg2000_init_component(Jpeg2000
              for (j = 0; j < 2; j++)
                  band->coord[1][j] = ff_jpeg2000_ceildiv(band->coord[1][j], dy);
  
-             band->prec = av_mallocz_array(reslevel->num_precincts_x *
-                                           (uint64_t)reslevel->num_precincts_y,
-                                           sizeof(*band->prec));
-             if (!band->prec)
++            if (reslevel->num_precincts_x * (uint64_t)reslevel->num_precincts_y > INT_MAX) {
++                band->prec = NULL;
 +                return AVERROR(ENOMEM);
++            }
              nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
+             band->prec = av_mallocz_array(nb_precincts, sizeof(*band->prec));
+             if (!band->prec)
+                 return AVERROR(ENOMEM);
  
              for (precno = 0; precno < nb_precincts; precno++) {
                  Jpeg2000Prec *prec = band->prec + precno;
                  if (!prec->zerobits)
                      return AVERROR(ENOMEM);
  
-                 prec->cblk = av_mallocz_array(prec->nb_codeblocks_width *
-                                               (uint64_t)prec->nb_codeblocks_height,
-                                               sizeof(*prec->cblk));
++                if (prec->nb_codeblocks_width * (uint64_t)prec->nb_codeblocks_height > INT_MAX) {
++                    prec->cblk = NULL;
++                    return AVERROR(ENOMEM);
++                }
+                 nb_codeblocks = prec->nb_codeblocks_width * prec->nb_codeblocks_height;
+                 prec->cblk = av_mallocz_array(nb_codeblocks, sizeof(*prec->cblk));
                  if (!prec->cblk)
                      return AVERROR(ENOMEM);
-                 for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
+                 for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
                      Jpeg2000Cblk *cblk = prec->cblk + cblkno;
                      uint16_t Cx0, Cy0;