sanity checks (should prevent hypothetical div by zero issue)
[ffmpeg.git] / libavcodec / wma.c
index 27a84ea..1f1495e 100644 (file)
@@ -72,6 +72,11 @@ int ff_wma_init(AVCodecContext * avctx, int flags2)
     int sample_rate1;
     int coef_vlc_table;
 
+    if(   avctx->sample_rate<=0 || avctx->sample_rate>50000
+       || avctx->channels<=0 || avctx->channels>8
+       || avctx->bit_rate<=0)
+        return -1;
+
     s->sample_rate = avctx->sample_rate;
     s->nb_channels = avctx->channels;
     s->bit_rate = avctx->bit_rate;
@@ -171,13 +176,13 @@ int ff_wma_init(AVCodecContext * avctx, int flags2)
             high_freq = high_freq * 0.5;
         }
     }
-    dprintf("flags2=0x%x\n", flags2);
-    dprintf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
+    dprintf(s->avctx, "flags2=0x%x\n", flags2);
+    dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
            s->version, s->nb_channels, s->sample_rate, s->bit_rate,
            s->block_align);
-    dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
+    dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
            bps, bps1, high_freq, s->byte_offset_bits);
-    dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
+    dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
            s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
 
     /* compute the scale factor band sizes for each MDCT block size */
@@ -302,7 +307,7 @@ int ff_wma_init(AVCodecContext * avctx, int flags2)
         window = av_malloc(sizeof(float) * n);
         alpha = M_PI / (2.0 * n);
         for(j=0;j<n;j++) {
-            window[n - j - 1] = sin((j + 0.5) * alpha);
+            window[j] = sin((j + 0.5) * alpha);
         }
         s->windows[i] = window;
     }