From d64ee9ff11d8712bbb0c643f902a62a0ee557021 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Wed, 26 May 2010 12:15:11 -0500 Subject: [PATCH] ole32: Fix seeking backwards in hglobalstream. --- dlls/ole32/hglobalstream.c | 19 +++++++++++-------- dlls/ole32/tests/hglobalstream.c | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dlls/ole32/hglobalstream.c b/dlls/ole32/hglobalstream.c index 5742f99619a..ef616defec5 100644 --- a/dlls/ole32/hglobalstream.c +++ b/dlls/ole32/hglobalstream.c @@ -371,12 +371,6 @@ static HRESULT WINAPI HGLOBALStreamImpl_Seek( TRACE("(%p, %x%08x, %d, %p)\n", iface, dlibMove.u.HighPart, dlibMove.u.LowPart, dwOrigin, plibNewPosition); - if (dlibMove.u.LowPart >= 0x80000000) - { - hr = STG_E_SEEKERROR; - goto end; - } - /* * The file pointer is moved depending on the given "function" * parameter. @@ -405,10 +399,19 @@ static HRESULT WINAPI HGLOBALStreamImpl_Seek( newPosition.u.HighPart = 0; newPosition.u.LowPart += dlibMove.QuadPart; -end: - if (plibNewPosition) *plibNewPosition = newPosition; + if (dlibMove.u.LowPart >= 0x80000000 && + newPosition.u.LowPart >= dlibMove.u.LowPart) + { + /* We tried to seek backwards and went past the start. */ + hr = STG_E_SEEKERROR; + goto end; + } + This->currentPosition = newPosition; +end: + if (plibNewPosition) *plibNewPosition = This->currentPosition; + return hr; } diff --git a/dlls/ole32/tests/hglobalstream.c b/dlls/ole32/tests/hglobalstream.c index 6d2230d5135..0810d9fa5d8 100644 --- a/dlls/ole32/tests/hglobalstream.c +++ b/dlls/ole32/tests/hglobalstream.c @@ -177,8 +177,8 @@ static void test_streamonhglobal(IStream *pStream) ll.u.HighPart = 0; ll.u.LowPart = -sizeof(data); hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull); - todo_wine ok_ole_success(hr, "IStream_Seek"); - todo_wine ok(ull.u.LowPart == 0, "LowPart set to %d\n", ull.u.LowPart); + ok_ole_success(hr, "IStream_Seek"); + ok(ull.u.LowPart == 0, "LowPart set to %d\n", ull.u.LowPart); ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart); /* IStream_Seek -- invalid LowPart value (seek to start of stream-1) */