Skip to content

Commit

Permalink
dsound: Set position past the end of the buffer is invalid.
Browse files Browse the repository at this point in the history
(cherry picked from commit 1941a91)

CW-Bug-Id: #22836
  • Loading branch information
Yuxuan Shui committed Dec 8, 2023
1 parent 926a670 commit 6082cd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dlls/dsound/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,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;

Expand Down
7 changes: 7 additions & 0 deletions dlls/dsound/tests/dsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down

0 comments on commit 6082cd7

Please sign in to comment.