]> git.sesse.net Git - ffmpeg/commitdiff
resample2: fix potential overflow
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 27 Oct 2011 12:34:45 +0000 (14:34 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 27 Oct 2011 12:34:45 +0000 (14:34 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/resample2.c
libswresample/resample2.c

index fc8ffea466561845d8e7b0da96fdfc3826ba29d8..5c425587abee1c4659088a64ead50477dba2bbb1 100644 (file)
@@ -248,10 +248,9 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
             dst[dst_index] = src[index2>>32];
             index2 += incr;
         }
-        frac += dst_index * dst_incr_frac;
         index += dst_index * dst_incr;
-        index += frac / c->src_incr;
-        frac %= c->src_incr;
+        index += (frac + dst_index * (int64_t)dst_incr_frac) / c->src_incr;
+        frac   = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
   }else{
     for(dst_index=0; dst_index < dst_size; dst_index++){
         FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);
index 5a2082478b5245c752720cb1219e8d649bfb816b..02f29bacf18f64a383adac7bbe57f79b1d963cef 100644 (file)
@@ -269,10 +269,9 @@ int swr_resample(AVResampleContext *c, short *dst, const short *src, int *consum
             dst[dst_index] = src[index2>>32];
             index2 += incr;
         }
-        frac += dst_index * dst_incr_frac;
         index += dst_index * dst_incr;
-        index += frac / c->src_incr;
-        frac %= c->src_incr;
+        index += (frac + dst_index * (int64_t)dst_incr_frac) / c->src_incr;
+        frac   = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
     }else{
         for(dst_index=0; dst_index < dst_size; dst_index++){
             FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);