diff --git a/dlls/ole32/stg_bigblockfile.c b/dlls/ole32/stg_bigblockfile.c index 0d28586c85e..b946ab071dd 100644 --- a/dlls/ole32/stg_bigblockfile.c +++ b/dlls/ole32/stg_bigblockfile.c @@ -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); } diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index a8a8f0bdde9..abf944ac7f0 100644 --- a/dlls/ole32/storage32.c +++ b/dlls/ole32/storage32.c @@ -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; diff --git a/dlls/ole32/storage32.h b/dlls/ole32/storage32.h index 884dc0e5ae3..4562772d32b 100644 --- a/dlls/ole32/storage32.h +++ b/dlls/ole32/storage32.h @@ -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);