From: Yuxuan Shui yshui@codeweavers.com
--- dlls/dsound/buffer.c | 11 +++++++---- dlls/dsound/tests/dsound.c | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index 1b724ee775b..b1434a6d1e6 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -574,12 +574,15 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuff IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface); HRESULT hres = DS_OK;
- TRACE("(%p,%ld)\n",This,newpos); + TRACE("(%p,%lu)\n",This,newpos); + + if (newpos >= This->buflen) { + return E_INVALIDARG; + }
AcquireSRWLockExclusive(&This->lock);
/* start mixing from this new location instead */ - newpos %= This->buflen; newpos -= newpos%This->pwfx->nBlockAlign; This->sec_mixpos = newpos;
@@ -1067,8 +1070,8 @@ HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *ds }
if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign) - dsb->buflen = dsbd->dwBufferBytes + - (dsbd->lpwfxFormat->nBlockAlign - + dsb->buflen = dsbd->dwBufferBytes + + (dsbd->lpwfxFormat->nBlockAlign - (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)); else dsb->buflen = dsbd->dwBufferBytes; diff --git a/dlls/dsound/tests/dsound.c b/dlls/dsound/tests/dsound.c index d5a3ccad8fd..9656a458415 100644 --- a/dlls/dsound/tests/dsound.c +++ b/dlls/dsound/tests/dsound.c @@ -919,6 +919,13 @@ static HRESULT test_block_align(LPGUID lpGuid) rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos2, NULL); ok(rc == DS_OK, "Could not get new position: %08lx\n", rc); ok(pos == pos2, "Positions not the same! Old position: %ld, new position: %ld\n", pos, pos2); + + /* Set position to past the end of the buffer */ + rc = IDirectSoundBuffer_SetCurrentPosition(secondary, wfx.nAvgBytesPerSec + 100); + ok(rc == E_INVALIDARG, "Set position to %lu succeeded\n", wfx.nAvgBytesPerSec + 100); + rc = IDirectSoundBuffer_GetCurrentPosition(secondary, &pos2, NULL); + ok(rc == DS_OK, "Could not get new position: %08lx\n", rc); + ok(pos == pos2, "Positions not the same! Old position: %ld, new position: %ld\n", pos, pos2); } ref=IDirectSoundBuffer_Release(secondary); ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d references, "