[FFmpeg-cvslog] resample: Fix overflow

Michael Niedermayer git at videolan.org
Thu Oct 27 14:45:24 CEST 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Oct 27 14:31:53 2011 +0200| [a67cb012e6947fb238193afc0f18114f6e20818c] | committer: Michael Niedermayer

resample: Fix overflow

Found-by: Jim Radford
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a67cb012e6947fb238193afc0f18114f6e20818c
---

 libavcodec/resample2.c    |    6 ++++--
 libswresample/resample2.c |    6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c
index b940059..fc8ffea 100644
--- a/libavcodec/resample2.c
+++ b/libavcodec/resample2.c
@@ -207,8 +207,10 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size,
     memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
     c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
 
-    c->src_incr= out_rate;
-    c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
+    if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2))
+        goto error;
+    c->ideal_dst_incr= c->dst_incr;
+
     c->index= -phase_count*((c->filter_length-1)/2);
 
     return c;
diff --git a/libswresample/resample2.c b/libswresample/resample2.c
index 6af2b6c..5a20824 100644
--- a/libswresample/resample2.c
+++ b/libswresample/resample2.c
@@ -224,8 +224,10 @@ AVResampleContext *swr_resample_init(AVResampleContext *c, int out_rate, int in_
     }
 
     c->compensation_distance= 0;
-    c->src_incr= out_rate;
-    c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
+    if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2))
+        goto error;
+    c->ideal_dst_incr= c->dst_incr;
+
     c->index= -phase_count*((c->filter_length-1)/2);
     c->frac= 0;
 



More information about the ffmpeg-cvslog mailing list