buffer,
&bytesRead);
+ if (bytesRead != RAW_DIRENTRY_SIZE)
+ return STG_E_READFAULT;
+
return hr;
}
offset.u.LowPart += cbRead;
}
+ else
+ {
+ resRead = STG_E_READFAULT;
+ break;
+ }
} while (cbTotalRead.QuadPart < size.QuadPart);
HeapFree(GetProcessHeap(),0,buffer);
offset.u.LowPart += cbRead;
}
+ else
+ {
+ resRead = STG_E_READFAULT;
+ break;
+ }
}while(cbTotalRead.QuadPart < size.QuadPart);
HeapFree(GetProcessHeap(), 0, buffer);
ULONG bytesToReadInBuffer;
ULONG blockIndex;
BYTE* bufferWalker;
+ ULARGE_INTEGER stream_size;
TRACE("(%p)-> %i %p %i %p\n",This, offset.u.LowPart, buffer, size, bytesRead);
*/
blockIndex = BlockChainStream_GetSectorOfOffset(This, blockNoInSequence);
- if (blockIndex == BLOCK_END_OF_CHAIN)
- return STG_E_DOCFILECORRUPT; /* We failed to find the starting block */
+ *bytesRead = 0;
+
+ stream_size = BlockChainStream_GetSize(This);
+ if (stream_size.QuadPart > offset.QuadPart)
+ size = min(stream_size.QuadPart - offset.QuadPart, size);
+ else
+ return S_OK;
/*
* Start reading the buffer.
*/
- *bytesRead = 0;
bufferWalker = buffer;
while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) )
break;
}
- return (size == 0) ? S_OK : STG_E_READFAULT;
+ return S_OK;
}
/******************************************************************************
&buffer,
&bytesRead);
+ if (SUCCEEDED(res) && bytesRead != sizeof(DWORD))
+ res = STG_E_READFAULT;
+
if (SUCCEEDED(res))
{
StorageUtl_ReadDWord((BYTE *)&buffer, 0, nextBlockInChain);
/*
* If we run out of space for the small block depot, enlarge it
*/
- if (SUCCEEDED(res))
+ if (SUCCEEDED(res) && bytesRead == sizeof(DWORD))
{
StorageUtl_ReadDWord((BYTE *)&buffer, 0, &nextBlockIndex);
ULONG blockIndex;
ULONG bytesReadFromBigBlockFile;
BYTE* bufferWalker;
+ ULARGE_INTEGER stream_size;
/*
* This should never happen on a small block file.
*/
assert(offset.u.HighPart==0);
+ *bytesRead = 0;
+
+ stream_size = SmallBlockChainStream_GetSize(This);
+ if (stream_size.QuadPart > offset.QuadPart)
+ size = min(stream_size.QuadPart - offset.QuadPart, size);
+ else
+ return S_OK;
+
/*
* Find the first block in the stream that contains part of the buffer.
*/
/*
* Start reading the buffer.
*/
- *bytesRead = 0;
bufferWalker = buffer;
while ( (size > 0) && (blockIndex != BLOCK_END_OF_CHAIN) )
if (FAILED(rc))
return rc;
+ if (!bytesReadFromBigBlockFile)
+ return STG_E_DOCFILECORRUPT;
+
/*
* Step to the next big block.
*/
offsetInBlock = (offsetInBlock + bytesReadFromBigBlockFile) % This->parentStorage->smallBlockSize;
}
- return (size == 0) ? S_OK : STG_E_READFAULT;
+ return S_OK;
}
/******************************************************************************
r = IStream_Commit(stm, STGC_DEFAULT );
ok(r==S_OK, "failed to commit stream\n");
+ /* Read past the end of the stream. */
+ pos.QuadPart = 3;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 3, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to read\n");
+ ok(count == 3, "read bytes past end of stream\n");
+ pos.QuadPart = 10;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 10, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to read\n");
+ ok(count == 0, "read bytes past end of stream\n");
+ pos.QuadPart = 10000;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 10000, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to read\n");
+ ok(count == 0, "read bytes past end of stream\n");
+
+ /* Convert to a big block stream, and read past the end. */
+ p.QuadPart = 5000;
+ r = IStream_SetSize(stm,p);
+ ok(r==S_OK, "failed to set pos\n");
+ pos.QuadPart = 4997;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 4997, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to read\n");
+ ok(count == 3, "read bytes past end of stream\n");
+ pos.QuadPart = 5001;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 5001, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to read\n");
+ ok(count == 0, "read bytes past end of stream\n");
+ pos.QuadPart = 10000;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 10000, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to read\n");
+ ok(count == 0, "read bytes past end of stream\n");
+
/* seek round a bit, reset the stream size */
pos.QuadPart = 0;
r = IStream_Seek(stm, pos, 3, &p );
r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
ok(r==S_OK, "failed to seek stream\n");
ok(p.QuadPart == 10, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to set pos\n");
+ ok(count == 0, "read bytes from empty stream\n");
+ pos.QuadPart = 10000;
+ r = IStream_Seek(stm, pos, STREAM_SEEK_SET, &p );
+ ok(r==S_OK, "failed to seek stream\n");
+ ok(p.QuadPart == 10000, "at wrong place\n");
+ r = IStream_Read(stm, buffer, sizeof buffer, &count );
+ ok(r==S_OK, "failed to set pos\n");
+ ok(count == 0, "read bytes from empty stream\n");
pos.QuadPart = 0;
r = IStream_Seek(stm, pos, STREAM_SEEK_END, &p );
ok(r==S_OK, "failed to seek stream\n");