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.
This commit is contained in:
Robert Shearman 2006-08-03 20:25:14 +01:00 committed by Alexandre Julliard
parent 6455b9e1a0
commit f0dc9deff0
3 changed files with 30 additions and 4 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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);