Andrew Eikum : dsound: Validate format in primary buffer's SetFormat().
Alexandre Julliard
julliard at winehq.org
Mon Dec 5 14:55:00 CST 2011
Module: wine
Branch: master
Commit: 287a6e8473cb40396b00556ced4f9b275f54ff8e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=287a6e8473cb40396b00556ced4f9b275f54ff8e
Author: Andrew Eikum <aeikum at codeweavers.com>
Date: Fri Dec 2 11:53:14 2011 -0600
dsound: Validate format in primary buffer's SetFormat().
---
dlls/dsound/primary.c | 6 ++
dlls/dsound/tests/dsound.c | 139 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+), 0 deletions(-)
diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c
index 3b61562..1cc59e5 100644
--- a/dlls/dsound/primary.c
+++ b/dlls/dsound/primary.c
@@ -374,6 +374,12 @@ HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passe
passed_fmt->nAvgBytesPerSec, passed_fmt->nBlockAlign,
passed_fmt->wBitsPerSample, passed_fmt->cbSize);
+ if(passed_fmt->wBitsPerSample < 8 || passed_fmt->wBitsPerSample % 8 != 0 ||
+ passed_fmt->nChannels == 0 || passed_fmt->nSamplesPerSec == 0 ||
+ passed_fmt->nAvgBytesPerSec == 0 ||
+ passed_fmt->nBlockAlign != passed_fmt->nChannels * passed_fmt->wBitsPerSample / 8)
+ return DSERR_INVALIDPARAM;
+
/* **** */
RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
EnterCriticalSection(&(device->mixlock));
diff --git a/dlls/dsound/tests/dsound.c b/dlls/dsound/tests/dsound.c
index 0c0239c..45dd00a 100644
--- a/dlls/dsound/tests/dsound.c
+++ b/dlls/dsound/tests/dsound.c
@@ -1221,6 +1221,144 @@ EXIT:
return rc;
}
+static HRESULT test_invalid_fmts(LPGUID lpGuid)
+{
+ HRESULT rc;
+ LPDIRECTSOUND dso=NULL;
+ LPDIRECTSOUNDBUFFER primary=NULL;
+ DSBUFFERDESC bufdesc;
+
+ /* Create the DirectSound object */
+ rc=pDirectSoundCreate(lpGuid,&dso,NULL);
+ ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
+ "DirectSoundCreate() failed: %08x\n",rc);
+ if (rc!=DS_OK)
+ return rc;
+
+ /* We must call SetCooperativeLevel before creating primary buffer */
+ /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
+ rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
+ ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
+ if (rc!=DS_OK){
+ IDirectSound_Release(dso);
+ return rc;
+ }
+
+ ZeroMemory(&bufdesc, sizeof(bufdesc));
+ bufdesc.dwSize=sizeof(bufdesc);
+ bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
+ rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
+ ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
+ "to create a primary buffer %08x\n",rc);
+
+ if (rc==DS_OK && primary!=NULL) {
+ WAVEFORMATEX wfx;
+
+ wfx.wFormatTag = WAVE_FORMAT_PCM;
+ wfx.nChannels = 0;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 0;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 2;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 12;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 0;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = 0;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = 0;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample / 8) - 1;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample / 8) + 1;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == E_INVALIDARG, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign + 1;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == S_OK, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign - 1;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == S_OK, "SetFormat: %08x\n", rc);
+
+ wfx.nChannels = 2;
+ wfx.nSamplesPerSec = 44100;
+ wfx.wBitsPerSample = 16;
+ wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
+ wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign + 1;
+ rc = IDirectSoundBuffer_SetFormat(primary, &wfx);
+ ok(rc == S_OK, "SetFormat: %08x\n", rc);
+
+ IDirectSoundBuffer_Release(primary);
+ }
+
+ IDirectSound_Release(dso);
+
+ return S_OK;
+}
+
static unsigned int number;
static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
@@ -1250,6 +1388,7 @@ static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
test_secondary(lpGuid);
test_frequency(lpGuid);
test_duplicate(lpGuid);
+ test_invalid_fmts(lpGuid);
}
return 1;
More information about the wine-cvs
mailing list