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(
}
/******************************************************************************
* BIGBLOCKFILE_GetBigBlock
* BIGBLOCKFILE_EnsureExists
*
* Returns the specified block.
* Will grow the file if necessary.
* Grows the file if necessary to make sure the block is valid.
*/
void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index)
void BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index)
{
/*
* block index starts at -1
......@@ -379,6 +378,27 @@ void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index)
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);
}
......
......@@ -2717,6 +2717,11 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
depotBlockOffset = 0;
}
/*
* make sure that the block physically exists before using it
*/
BIGBLOCKFILE_EnsureExists(This->bigBlockFile, freeBlock);
This->prevFreeBlock = freeBlock;
return freeBlock;
......
......@@ -190,6 +190,7 @@ BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
ULONG blocksize,
BOOL fileBased);
void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
void BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index);
void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index);
void* BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This, ULONG index);
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