From 666446bfaa7378918c8bf917cab1ca7555c0d4aa Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Fri, 25 Feb 2011 16:00:26 +0000 Subject: [PATCH] [WDMAUD.DRV] - Check if the provided waveformat is at least size of WAVEFORMAT - Compute extra details such as the size or wBitsPerSample from the provided members - Backup i/o completion handle before commiting the audio buffer as the struct might have already been released - Fixes playback of mmsys cpl - Found by DPH! svn path=/trunk/; revision=50900 --- reactos/dll/win32/wdmaud.drv/legacy.c | 29 +++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/reactos/dll/win32/wdmaud.drv/legacy.c b/reactos/dll/win32/wdmaud.drv/legacy.c index f1d01e795ba..55189178572 100644 --- a/reactos/dll/win32/wdmaud.drv/legacy.c +++ b/reactos/dll/win32/wdmaud.drv/legacy.c @@ -476,7 +476,7 @@ WdmAudSetWaveDeviceFormatByLegacy( DeviceInfo.u.WaveFormatEx.nSamplesPerSec = WaveFormat->nSamplesPerSec; DeviceInfo.u.WaveFormatEx.nBlockAlign = WaveFormat->nBlockAlign; DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec = WaveFormat->nAvgBytesPerSec; - DeviceInfo.u.WaveFormatEx.wBitsPerSample = WaveFormat->wBitsPerSample; + DeviceInfo.u.WaveFormatEx.wBitsPerSample = (DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec * 8) / (DeviceInfo.u.WaveFormatEx.nSamplesPerSec * DeviceInfo.u.WaveFormatEx.nChannels); #endif Result = SyncOverlappedDeviceIoControl(KernelHandle, @@ -492,14 +492,19 @@ WdmAudSetWaveDeviceFormatByLegacy( return TranslateInternalMmResult(Result); } - /* Store format */ - Instance->WaveFormatEx.cbSize = WaveFormat->cbSize; - Instance->WaveFormatEx.wFormatTag = WaveFormat->wFormatTag; - Instance->WaveFormatEx.nChannels = WaveFormat->nChannels; - Instance->WaveFormatEx.nSamplesPerSec = WaveFormat->nSamplesPerSec; - Instance->WaveFormatEx.nBlockAlign = WaveFormat->nBlockAlign; - Instance->WaveFormatEx.nAvgBytesPerSec = WaveFormat->nAvgBytesPerSec; - Instance->WaveFormatEx.wBitsPerSample = WaveFormat->wBitsPerSample; + if (WaveFormatSize >= sizeof(WAVEFORMAT)) + { + /* Store format */ + Instance->WaveFormatEx.wFormatTag = WaveFormat->wFormatTag; + Instance->WaveFormatEx.nChannels = WaveFormat->nChannels; + Instance->WaveFormatEx.nSamplesPerSec = WaveFormat->nSamplesPerSec; + Instance->WaveFormatEx.nBlockAlign = WaveFormat->nBlockAlign; + Instance->WaveFormatEx.nAvgBytesPerSec = WaveFormat->nAvgBytesPerSec; + } + + /* store details */ + Instance->WaveFormatEx.cbSize = sizeof(WAVEFORMATEX); + Instance->WaveFormatEx.wBitsPerSample = (DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec * 8) / (DeviceInfo.u.WaveFormatEx.nSamplesPerSec * DeviceInfo.u.WaveFormatEx.nChannels); /* Store sound device handle instance handle */ Instance->Handle = (PVOID)DeviceInfo.hDevice; @@ -617,7 +622,7 @@ WdmAudCommitWaveBufferByLegacy( // create completion event - Overlap->Standard.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); + Overlap->Standard.hEvent = Handle = CreateEventW(NULL, FALSE, FALSE, NULL); if (Overlap->Standard.hEvent == NULL) { // no memory @@ -641,13 +646,11 @@ WdmAudCommitWaveBufferByLegacy( } // close event handle - CloseHandle(Overlap->Standard.hEvent); + CloseHandle(Handle); return MMSYSERR_NOERROR; } - - MMRESULT WdmAudSetWaveStateByLegacy( IN struct _SOUND_DEVICE_INSTANCE* SoundDeviceInstance, -- 2.17.1