Skip to content

Commit

Permalink
Doppler effect sound effects cause buffer overread
Browse files Browse the repository at this point in the history
Sounds that use dopplerScale (e.g., rocket launcher) exhibited a buffer
over-read. S_PaintChannelFrom16's ofst reads past end of sfx->pSoundData buffer.
To resolve this, take dopplerScale increments of ofst into consideration when
calculating count, which controls the loop for ofst.

Resolves: #1038
See also: 69800e8
  • Loading branch information
namtsui authored and xycaleth committed Jun 9, 2020
1 parent 4974446 commit 0218d2d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions codemp/client/snd_mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,6 @@ static void S_PaintChannelFrom16( channel_t *ch, const sfx_t *sfx, int count, in

for ( int i=0 ; i<count ; i++ )
{
// have we run off the end?
if ((int)ofst >= sfx->iSoundLengthInSamples)
break;
iData = sfx->pSoundData[ (int)ofst ];

pSamplesDest[i].left += (iData * iLeftVol )>>8;
Expand Down Expand Up @@ -446,8 +443,20 @@ void S_PaintChannels( int endtime ) {
}

count = end - ltime;
if ( sampleOffset + count > sc->iSoundLengthInSamples ) {
count = sc->iSoundLengthInSamples - sampleOffset;
if ( ch->doppler && ch->dopplerScale > 1 ) {
if ( sampleOffset + (count * ch->dopplerScale) > sc->iSoundLengthInSamples ) {
count = (sc->iSoundLengthInSamples - sampleOffset) / ch->dopplerScale;

// avoid infinite loop once length of remaining pSoundData (numerator)
// is smaller than dopplerScale (denominator), resulting in 0.
if ( count == 0 ) {
break;
}
}
} else {
if ( sampleOffset + count > sc->iSoundLengthInSamples ) {
count = sc->iSoundLengthInSamples - sampleOffset;
}
}

if ( count > 0 ) {
Expand Down

0 comments on commit 0218d2d

Please sign in to comment.