Merge commit '74f6df745a05d3d8b3dcfc28992c69a70ae87957' into release/2.2
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 14 Jul 2014 20:37:59 +0000 (22:37 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 14 Jul 2014 20:38:22 +0000 (22:38 +0200)
* commit '74f6df745a05d3d8b3dcfc28992c69a70ae87957':
  jpeg2000: fix dereferencing invalid pointers during cleanup

Conflicts:
libavcodec/jpeg2000.c

See: 09927f3eaa93e31dd90ab8ee66dc1ad867b3365f
See: 912ce9dd2080c5837285a471d750fa311e09b555
See: 9e477a37703318cb86d8ed1d426929235aa02b67
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/jpeg2000.c

@@@ -368,9 -372,9 +368,9 @@@ 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_calloc(reslevel->num_precincts_x *
-                                          (uint64_t)reslevel->num_precincts_y,
-                                          sizeof(*band->prec));
+             band->prec = av_mallocz_array(reslevel->num_precincts_x *
 -                                          reslevel->num_precincts_y,
++                                          (uint64_t)reslevel->num_precincts_y,
+                                           sizeof(*band->prec));
              if (!band->prec)
                  return AVERROR(ENOMEM);
  
@@@ -504,22 -487,33 +504,29 @@@ void ff_jpeg2000_cleanup(Jpeg2000Compon
      for (reslevelno = 0;
           comp->reslevel && reslevelno < codsty->nreslevels;
           reslevelno++) {
-         Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
+         Jpeg2000ResLevel *reslevel;
+         if (!comp->reslevel)
+             continue;
  
+         reslevel = comp->reslevel + reslevelno;
          for (bandno = 0; bandno < reslevel->nbands; bandno++) {
-             if (reslevel->band) {
-                 Jpeg2000Band *band = reslevel->band + bandno;
-                 for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
-                     if (band->prec) {
-                         Jpeg2000Prec *prec = band->prec + precno;
-                         av_freep(&prec->zerobits);
-                         av_freep(&prec->cblkincl);
-                         av_freep(&prec->cblk);
-                     }
+             Jpeg2000Band *band;
+             if (!reslevel->band)
+                 continue;
+             band = reslevel->band + bandno;
+             for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
 -                Jpeg2000Prec *prec;
 -
 -                if (!band->prec)
 -                    continue;
 -
 -                prec = band->prec + precno;
 -                av_freep(&prec->zerobits);
 -                av_freep(&prec->cblkincl);
 -                av_freep(&prec->cblk);
 -
++                if (band->prec) {
++                    Jpeg2000Prec *prec = band->prec + precno;
++                    av_freep(&prec->zerobits);
++                    av_freep(&prec->cblkincl);
++                    av_freep(&prec->cblk);
 +                }
-                 av_freep(&band->prec);
              }
+             av_freep(&band->prec);
          }
          av_freep(&reslevel->band);
      }