Skip to content

Commit

Permalink
Disable broken idSIMD_SSE::UpSampleOGGTo44kHz()
Browse files Browse the repository at this point in the history
It corrupted the stack when called with buffers allocated on the stack
and numSamples that are not a multiple of four, apparently, by writing
4 floats too many, at least in the 22KHz Stereo case..

This caused the crash described in
  dhewm/dhewm3#303 (comment)

Now it just uses the generic C code, like all platforms besides MSVC/x86
already do.
  • Loading branch information
DanielGibson authored and IvanTheB committed Apr 29, 2023
1 parent 6cda0d4 commit b02bcc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions idlib/math/Simd_SSE.cpp
Expand Up @@ -17164,6 +17164,10 @@ void idSIMD_SSE::UpSamplePCMTo44kHz( float *dest, const short *src, const int nu
}
}


// DG: at least in the 22KHz Stereo OGG case with numSamples % 4 != 0 this is broken (writes 4 floats too much which can destroy the stack, see #303),
// so let's just not use it anymore its MSVC+32bit only anyway and I doubt it gets noticeable speedups, so I don't feel like trying to understand and fix it..
#if 0
/*
============
SSE_UpSample11kHzMonoOGGTo44kHz
Expand Down Expand Up @@ -17474,6 +17478,7 @@ void idSIMD_SSE::UpSampleOGGTo44kHz( float *dest, const float * const *ogg, cons
assert( 0 );
}
}
#endif // 0 (DG: commenting out all the OGG-related SSE code)

/*
============
Expand Down
3 changes: 2 additions & 1 deletion idlib/math/Simd_SSE.h
Expand Up @@ -135,7 +135,8 @@ class idSIMD_SSE : public idSIMD_MMX {
virtual int VPCALL CreateVertexProgramShadowCache( idVec4 *vertexCache, const idDrawVert *verts, const int numVerts );

virtual void VPCALL UpSamplePCMTo44kHz( float *dest, const short *pcm, const int numSamples, const int kHz, const int numChannels );
virtual void VPCALL UpSampleOGGTo44kHz( float *dest, const float * const *ogg, const int numSamples, const int kHz, const int numChannels );
// DG: the following is broken at least in the 22KHz Stereo case with numSamples % 4 != 0 (writes 4 floats too much which can destroy the stack), so let's not use it anymore.
//virtual void VPCALL UpSampleOGGTo44kHz( float *dest, const float * const *ogg, const int numSamples, const int kHz, const int numChannels );
virtual void VPCALL MixSoundTwoSpeakerMono( float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2] );
virtual void VPCALL MixSoundTwoSpeakerStereo( float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2] );
virtual void VPCALL MixSoundSixSpeakerMono( float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6] );
Expand Down

0 comments on commit b02bcc5

Please sign in to comment.