engine: soundlib: fix possible buffer overflow in Sound_ConvertUpsample
This commit is contained in:
parent
103b9724f9
commit
f4a77308ec
1 changed files with 5 additions and 4 deletions
|
@ -272,13 +272,14 @@ static qboolean Sound_ConvertDownsample( wavdata_t *sc, int inwidth, int outwidt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static qboolean Sound_ConvertUpsample( wavdata_t *sc, int inwidth, int outwidth, int outcount, double stepscale )
|
static qboolean Sound_ConvertUpsample( wavdata_t *sc, int inwidth, int outwidth, int outcount, int incount, double stepscale )
|
||||||
{
|
{
|
||||||
const int incount = ( outcount * stepscale ) - 1;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
double j;
|
double j;
|
||||||
double frac;
|
double frac;
|
||||||
|
|
||||||
|
incount--; // to not go past last sample while interpolating
|
||||||
|
|
||||||
if( inwidth == 1 )
|
if( inwidth == 1 )
|
||||||
{
|
{
|
||||||
int8_t *data = (int8_t *)sc->buffer;
|
int8_t *data = (int8_t *)sc->buffer;
|
||||||
|
@ -449,7 +450,7 @@ static qboolean Sound_ResampleInternal( wavdata_t *sc, int inrate, int inwidth,
|
||||||
qboolean handled = false;
|
qboolean handled = false;
|
||||||
double stepscale;
|
double stepscale;
|
||||||
double t1, t2;
|
double t1, t2;
|
||||||
int outcount;
|
int outcount, incount = sc->samples;
|
||||||
|
|
||||||
if( inrate == outrate && inwidth == outwidth )
|
if( inrate == outrate && inwidth == outwidth )
|
||||||
return false;
|
return false;
|
||||||
|
@ -496,7 +497,7 @@ static qboolean Sound_ResampleInternal( wavdata_t *sc, int inrate, int inwidth,
|
||||||
else if( inrate > outrate ) // fast case, usually downsample but is also ok for upsampling
|
else if( inrate > outrate ) // fast case, usually downsample but is also ok for upsampling
|
||||||
handled = Sound_ConvertDownsample( sc, inwidth, outwidth, outcount, stepscale );
|
handled = Sound_ConvertDownsample( sc, inwidth, outwidth, outcount, stepscale );
|
||||||
else // upsample case, w/ interpolation
|
else // upsample case, w/ interpolation
|
||||||
handled = Sound_ConvertUpsample( sc, inwidth, outwidth, outcount, stepscale );
|
handled = Sound_ConvertUpsample( sc, inwidth, outwidth, outcount, incount, stepscale );
|
||||||
|
|
||||||
t2 = Sys_DoubleTime();
|
t2 = Sys_DoubleTime();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue