Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/mfplat/main.c | 14 +++++++++++++- dlls/mfplat/tests/mfplat.c | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c index 7fd713261fc..be063fa1e55 100644 --- a/dlls/mfplat/main.c +++ b/dlls/mfplat/main.c @@ -3843,7 +3843,7 @@ static HRESULT WINAPI bytestream_file_IsEndOfStream(IMFByteStream *iface, BOOL * static HRESULT WINAPI bytestream_file_Read(IMFByteStream *iface, BYTE *buffer, ULONG size, ULONG *read_len) { struct bytestream *stream = impl_from_IMFByteStream(iface); - LARGE_INTEGER position; + LARGE_INTEGER position, file_size; HRESULT hr = S_OK; BOOL ret;
@@ -3851,6 +3851,18 @@ static HRESULT WINAPI bytestream_file_Read(IMFByteStream *iface, BYTE *buffer, U
EnterCriticalSection(&stream->cs);
+ if (!GetFileSizeEx(stream->hfile, &file_size)) + { + LeaveCriticalSection(&stream->cs); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (stream->position > file_size.QuadPart) + { + LeaveCriticalSection(&stream->cs); + return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); + } + position.QuadPart = stream->position; if ((ret = SetFilePointerEx(stream->hfile, position, NULL, FILE_BEGIN))) { diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 1b51cd73dc3..84b35386463 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -2031,8 +2031,8 @@ static void test_file_stream(void)
size = 0xdeadbeef; hr = IMFByteStream_Read(bytestream, data, sizeof(data), &size); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF), "Unexpected hr %#x.\n", hr); - todo_wine ok(size == 0xdeadbeef, "Got size %u.\n", size); + ok(hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF), "Unexpected hr %#x.\n", hr); + ok(size == 0xdeadbeef, "Got size %u.\n", size);
hr = IMFByteStream_SetCurrentPosition(bytestream, bytestream_length - 4); ok(hr == S_OK, "Failed to set bytestream position, hr %#x.\n", hr);