From 930e0cdc08785ecb30dad7d2a592da1887d93ba7 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Fri, 22 Feb 2019 19:27:00 -0600 Subject: [PATCH] quartz/filesource: Correctly report short reads from IAsyncReader_SyncRead(). Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/quartz/filesource.c | 35 ++++++++++++++++++---------------- dlls/quartz/tests/filesource.c | 2 -- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/dlls/quartz/filesource.c b/dlls/quartz/filesource.c index 6b8bfa33534..11b9712c2c1 100644 --- a/dlls/quartz/filesource.c +++ b/dlls/quartz/filesource.c @@ -1309,34 +1309,37 @@ static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMed return hr; } -static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer) +static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader *iface, + LONGLONG offset, LONG length, BYTE *buffer) { OVERLAPPED ovl; - HRESULT hr = S_OK; - FileAsyncReader *This = impl_from_IAsyncReader(iface); + FileAsyncReader *filter = impl_from_IAsyncReader(iface); + DWORD read_len; + HRESULT hr; + BOOL ret; - TRACE("%p->(%s, %d, %p)\n", This, wine_dbgstr_longlong(llPosition), lLength, pBuffer); + TRACE("filter %p, offset %s, length %d, buffer %p.\n", + filter, wine_dbgstr_longlong(offset), length, buffer); ZeroMemory(&ovl, sizeof(ovl)); ovl.hEvent = CreateEventW(NULL, 0, 0, NULL); /* NOTE: llPosition is the actual byte position to start reading from */ - ovl.u.s.Offset = (DWORD) llPosition; - ovl.u.s.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8)); + ovl.u.s.Offset = (DWORD)offset; + ovl.u.s.OffsetHigh = (DWORD)(offset >> (sizeof(DWORD) * 8)); - if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl)) - hr = HRESULT_FROM_WIN32(GetLastError()); - - if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING)) - hr = S_OK; - - if (SUCCEEDED(hr)) + ret = ReadFile(filter->hFile, buffer, length, NULL, &ovl); + if (ret || GetLastError() == ERROR_IO_PENDING) { - DWORD dwBytesRead; - - if (!GetOverlappedResult(This->hFile, &ovl, &dwBytesRead, TRUE)) + if (GetOverlappedResult(filter->hFile, &ovl, &read_len, TRUE)) + hr = (read_len == length) ? S_OK : S_FALSE; + else hr = HRESULT_FROM_WIN32(GetLastError()); } + else if (GetLastError() == ERROR_HANDLE_EOF) + hr = S_FALSE; + else + hr = HRESULT_FROM_WIN32(GetLastError()); CloseHandle(ovl.hEvent); diff --git a/dlls/quartz/tests/filesource.c b/dlls/quartz/tests/filesource.c index 7f25596ae35..e13cb05a70c 100644 --- a/dlls/quartz/tests/filesource.c +++ b/dlls/quartz/tests/filesource.c @@ -722,7 +722,6 @@ static void test_async_reader(void) ok(buffer[i] == (10 + i) % 111, "Got wrong byte %02x at %u.\n", buffer[i], i); hr = IAsyncReader_SyncRead(reader, 590, 20, buffer); -todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); for (i = 0; i < 10; i++) ok(buffer[i] == (590 + i) % 111, "Got wrong byte %02x at %u.\n", buffer[i], i); @@ -731,7 +730,6 @@ todo_wine memset(buffer, 0xcc, sizeof(buffer)); hr = IAsyncReader_SyncRead(reader, 600, 10, buffer); -todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); ok(buffer[0] == 0xcc, "Got wrong byte %02x.\n", buffer[0]);