diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-03-05 13:33:57 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-03-05 13:33:57 +0000 |
commit | f5f5786af237c38800b4c4a0132457c2fb4c0185 (patch) | |
tree | 4e307ded4b7a4d138aef44fe93d4eb587b3b6ae7 | |
parent | 07bfbcb2b4bb13ee62a02c1312c5f9bdb530e806 (diff) |
Fixed bug where resample may write pass the output buffer
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@287 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjmedia/src/pjmedia/resample.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/pjmedia/src/pjmedia/resample.c b/pjmedia/src/pjmedia/resample.c index 0fd08468..83ec9f97 100644 --- a/pjmedia/src/pjmedia/resample.c +++ b/pjmedia/src/pjmedia/resample.c @@ -38,6 +38,9 @@ * - move FilterUp() and FilterUD() from filterkit.c * - move stddefs.h and resample.h to this file. * - const correctness. + * - fixed SrcLinear() may write pass output buffer. + * - assume the same for SrcUp() and SrcUD(), so put the same + * protection. */ #include <pjmedia/resample.h> #include <pjmedia/errno.h> @@ -203,7 +206,7 @@ static int HWORD iconst; UWORD time = 0; const HWORD *xp; - HWORD *Ystart; + HWORD *Ystart, *Yend; WORD v,x1,x2; double dt; /* Step through input signal */ @@ -214,8 +217,9 @@ static int dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ Ystart = Y; + Yend = Ystart + (unsigned)(nx * pFactor); endTime = time + (1<<Np)*(WORD)nx; - while (time < endTime) + while (time < endTime && Y < Yend) /* bennylp fix: added Y < Yend */ { iconst = (time) & Pmask; xp = &X[(time)>>Np]; /* Ptr to current input sample */ @@ -340,7 +344,7 @@ static int SrcUp(const HWORD X[], HWORD Y[], double pFactor, const HWORD pImp[], const HWORD pImpD[], BOOL Interp) { const HWORD *xp; - HWORD *Ystart; + HWORD *Ystart, *Yend; WORD v; double dt; /* Step through input signal */ @@ -352,8 +356,9 @@ static int SrcUp(const HWORD X[], HWORD Y[], double pFactor, dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ Ystart = Y; + Yend = Ystart + (unsigned)(nx * pFactor); endTime = time + (1<<Np)*(WORD)nx; - while (time < endTime) + while (time < endTime && Y < Yend) /* bennylp fix: protect Y */ { xp = &X[time>>Np]; /* Ptr to current input sample */ /* Perform left-wing inner product */ @@ -379,7 +384,7 @@ static int SrcUD(const HWORD X[], HWORD Y[], double pFactor, const HWORD pImp[], const HWORD pImpD[], BOOL Interp) { const HWORD *xp; - HWORD *Ystart; + HWORD *Ystart, *Yend; WORD v; double dh; /* Step through filter impulse response */ @@ -395,8 +400,9 @@ static int SrcUD(const HWORD X[], HWORD Y[], double pFactor, dhb = dh*(1<<Na) + 0.5; /* Fixed-point representation */ Ystart = Y; + Yend = Ystart + (unsigned)(nx * pFactor); endTime = time + (1<<Np)*(WORD)nx; - while (time < endTime) + while (time < endTime && Y < Yend) /* bennylp fix: protect Y */ { xp = &X[time>>Np]; /* Ptr to current input sample */ v = FilterUD(pImp, pImpD, pNwing, Interp, xp, (HWORD)(time&Pmask), |