From 0de8d01b09b1cc7ca34f7ae3890b4a416ff801fe Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Wed, 30 Mar 2022 14:57:44 +0200 Subject: [PATCH] winmm: Properly handle mmioRead/mmioWrite in case of errors. In C, an inequality comparison between a signed and an unsigned integer ends up with an unsigned comparison. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52628 Signed-off-by: Eric Pouech Signed-off-by: Andrew Eikum Signed-off-by: Alexandre Julliard --- dlls/winmm/mmio.c | 4 ++-- dlls/winmm/playsound.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c index 352da62a215..d61b3c90c49 100644 --- a/dlls/winmm/mmio.c +++ b/dlls/winmm/mmio.c @@ -1234,7 +1234,7 @@ MMRESULT WINAPI mmioDescend(HMMIO hmmio, LPMMCKINFO lpck, LONG ix; ix = mmioRead(hmmio, (LPSTR)lpck, 3 * sizeof(DWORD)); - if (ix < 2*sizeof(DWORD)) + if (ix < 0 || ix < 2*sizeof(DWORD)) { mmioSeek(hmmio, dwOldPos, SEEK_SET); WARN("return ChunkNotFound\n"); @@ -1336,7 +1336,7 @@ MMRESULT WINAPI mmioCreateChunk(HMMIO hmmio, MMCKINFO* lpck, UINT uFlags) ix = mmioWrite(hmmio, (LPSTR)lpck, size); TRACE("after mmioWrite ix = %ld req = %ld, errno = %d\n", ix, size, errno); - if (ix < size) { + if (ix != size) { mmioSeek(hmmio, dwOldPos, SEEK_SET); WARN("return CannotWrite\n"); return MMIOERR_CANNOTWRITE; diff --git a/dlls/winmm/playsound.c b/dlls/winmm/playsound.c index 0858f958583..d844bf9b0ab 100644 --- a/dlls/winmm/playsound.c +++ b/dlls/winmm/playsound.c @@ -262,6 +262,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) INT count, bufsize, left, index; struct playsound_data s; void* data; + LONG r; s.hEvent = 0; @@ -361,7 +362,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize); if (!lpWaveFormat) goto errCleanUp; - if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT)) + r = mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize); + if (r < 0 || r < sizeof(PCMWAVEFORMAT)) goto errCleanUp; TRACE("wFormatTag=%04X !\n", lpWaveFormat->wFormatTag);