When This->dwPos is bigger than This->dwLength (caused by seeking) the old function calculated a wrong number of bytes available. The null check for out pointer is not necessary (crashes on windows) --- dlls/shlwapi/regstream.c | 25 +++++++++++-------------- 1 files changed, 11 insertions(+), 14 deletions(-) diff --git a/dlls/shlwapi/regstream.c b/dlls/shlwapi/regstream.c index ac1e6e6..f7cf16e 100644 --- a/dlls/shlwapi/regstream.c +++ b/dlls/shlwapi/regstream.c @@ -116,24 +116,21 @@ static ULONG WINAPI IStream_fnRelease(IStream *iface) static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead) { ISHRegStream *This = (ISHRegStream *)iface; - - DWORD dwBytesToRead, dwBytesLeft; + DWORD dwBytesToRead; TRACE("(%p)->(%p,0x%08x,%p)\n",This, pv, cb, pcbRead); - if (!pv) - return STG_E_INVALIDPOINTER; - - dwBytesLeft = This->dwLength - This->dwPos; - - if ( 0 >= dwBytesLeft ) /* end of buffer */ - return S_FALSE; - - dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb; + if (This->dwPos >= This->dwLength) + dwBytesToRead = 0; + else + dwBytesToRead = This->dwLength - This->dwPos; - memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead); - - This->dwPos += dwBytesToRead; /* adjust pointer */ + dwBytesToRead = (cb > dwBytesToRead) ? dwBytesToRead : cb; + if (dwBytesToRead != 0) /* not at end of buffer and we want to read something */ + { + memmove(pv, This->pbBuffer + This->dwPos, dwBytesToRead); + This->dwPos += dwBytesToRead; /* adjust pointer */ + } if (pcbRead) *pcbRead = dwBytesToRead; -- 1.6.4.2