AAC encoder: fix undefined behavior
authorClaudio Freire <klaussfreire@gmail.com>
Wed, 30 Mar 2016 21:34:08 +0000 (18:34 -0300)
committerClaudio Freire <klaussfreire@gmail.com>
Thu, 31 Mar 2016 01:35:28 +0000 (22:35 -0300)
Fix uninitialized access of minsf in short windows
Fix potential invocation of coef2minsf(0)

libavcodec/aaccoder_twoloop.h

index 4747c79..41d3ffd 100644 (file)
@@ -300,8 +300,12 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
         start = w*128;
         for (g = 0;  g < sce->ics.num_swb; g++) {
             const float *scaled = s->scoefs + start;
+            int minsfidx;
             maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
-            minsf[w*16+g] = coef2minsf(maxvals[w*16+g]);
+            if (maxvals[w*16+g] > 0)
+                minsfidx = coef2minsf(maxvals[w*16+g]);
+            for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)
+                minsf[(w+w2)*16+g] = minsfidx;
             start += sce->ics.swb_sizes[g];
         }
     }