Commit d54e7cd5 authored by Jinoh Kang's avatar Jinoh Kang Committed by Alexandre Julliard

combase: Fix reading from beyond the end of a HGLOBAL stream.

parent b3fbc16f
......@@ -151,7 +151,10 @@ static HRESULT WINAPI stream_Read(IStream *iface, void *pv, ULONG cb, ULONG *rea
if (!read_len)
read_len = &dummy;
len = min(stream->handle->size - stream->position.u.LowPart, cb);
if (stream->handle->size >= stream->position.u.LowPart)
len = min(stream->handle->size - stream->position.u.LowPart, cb);
else
len = 0;
buffer = GlobalLock(stream->handle->hglobal);
if (!buffer)
......
......@@ -65,6 +65,25 @@ static void test_streamonhglobal(void)
hr = IStream_Write(pStream, data, sizeof(data), NULL);
ok_ole_success(hr, "IStream_Write");
/* Seek beyond the end of the stream and read from it */
ll.QuadPart = sizeof(data) + 16;
hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, NULL);
ok_ole_success(hr, "IStream_Seek");
hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
ok_ole_success(hr, "IStream_Read");
ok(read == 0, "IStream_Read returned read %ld\n", read);
ull.u.HighPart = 0xCAFECAFE;
ull.u.LowPart = 0xCAFECAFE;
ll.u.HighPart = 0;
ll.u.LowPart = 0;
hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
ok_ole_success(hr, "IStream_Seek");
ok(ull.u.LowPart == sizeof(data) + 16, "LowPart set to %ld\n", ull.u.LowPart);
ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
/* Seek to the start of the stream and read from it */
ll.QuadPart = 0;
hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, NULL);
ok_ole_success(hr, "IStream_Seek");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment