Commit f0dc9def authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

ole32: Ensure that a returned free block is valid in storage.

Otherwise, an IStream_SetSize call followed by an IStream_Read call could fail with STG_E_DOCFILECORRUPT.
parent 6455b9e1
...@@ -351,12 +351,11 @@ void* BIGBLOCKFILE_GetROBigBlock( ...@@ -351,12 +351,11 @@ void* BIGBLOCKFILE_GetROBigBlock(
} }
/****************************************************************************** /******************************************************************************
* BIGBLOCKFILE_GetBigBlock * BIGBLOCKFILE_EnsureExists
* *
* Returns the specified block. * Grows the file if necessary to make sure the block is valid.
* Will grow the file if necessary.
*/ */
void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index) void BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index)
{ {
/* /*
* block index starts at -1 * block index starts at -1
...@@ -379,6 +378,27 @@ void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index) ...@@ -379,6 +378,27 @@ void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index)
BIGBLOCKFILE_SetSize(This, newSize); BIGBLOCKFILE_SetSize(This, newSize);
} }
}
/******************************************************************************
* BIGBLOCKFILE_GetBigBlock
*
* Returns the specified block.
* Will grow the file if necessary.
*/
void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index)
{
/* FIXME: is this necessary? */
BIGBLOCKFILE_EnsureExists(This, index);
/*
* block index starts at -1
* translate to zero based index
*/
if (index == 0xffffffff)
index = 0;
else
index++;
return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_WRITE); return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_WRITE);
} }
......
...@@ -2717,6 +2717,11 @@ static ULONG StorageImpl_GetNextFreeBigBlock( ...@@ -2717,6 +2717,11 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
depotBlockOffset = 0; depotBlockOffset = 0;
} }
/*
* make sure that the block physically exists before using it
*/
BIGBLOCKFILE_EnsureExists(This->bigBlockFile, freeBlock);
This->prevFreeBlock = freeBlock; This->prevFreeBlock = freeBlock;
return freeBlock; return freeBlock;
......
...@@ -190,6 +190,7 @@ BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile, ...@@ -190,6 +190,7 @@ BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
ULONG blocksize, ULONG blocksize,
BOOL fileBased); BOOL fileBased);
void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This); void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
void BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index);
void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index); void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index);
void* BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This, ULONG index); void* BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This, ULONG index);
void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock); void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock);
......
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