From 2cee7ac6d94e2273499dc2c3e19885af40ca27f1 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Mon, 19 Jan 2004 21:44:02 +0000 Subject: [PATCH] Don't use CreateFileMapping on a zero length file. --- dlls/ole32/stg_bigblockfile.c | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/dlls/ole32/stg_bigblockfile.c b/dlls/ole32/stg_bigblockfile.c index d76602926d2..323f05df47a 100644 --- a/dlls/ole32/stg_bigblockfile.c +++ b/dlls/ole32/stg_bigblockfile.c @@ -222,23 +222,28 @@ static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile) if (This->hfile == INVALID_HANDLE_VALUE) return FALSE; - /* create the file mapping object - */ - This->hfilemap = CreateFileMappingA(This->hfile, - NULL, - This->flProtect, - 0, 0, - NULL); - - if (!This->hfilemap) - { - CloseHandle(This->hfile); - return FALSE; - } - This->filesize.s.LowPart = GetFileSize(This->hfile, &This->filesize.s.HighPart); + if( This->filesize.s.LowPart || This->filesize.s.HighPart ) + { + /* create the file mapping object + */ + This->hfilemap = CreateFileMappingA(This->hfile, + NULL, + This->flProtect, + 0, 0, + NULL); + + if (!This->hfilemap) + { + CloseHandle(This->hfile); + return FALSE; + } + } + else + This->hfilemap = NULL; + This->maplist = NULL; TRACE("file len %lu\n", This->filesize.s.LowPart); @@ -420,7 +425,8 @@ void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize) /* * close file-mapping object, must be done before call to SetEndFile */ - CloseHandle(This->hfilemap); + if( This->hfilemap ) + CloseHandle(This->hfilemap); This->hfilemap = 0; /* @@ -662,6 +668,9 @@ static BOOL BIGBLOCKFILE_MapPage(LPBIGBLOCKFILE This, MappedPage *page) DWORD numBytesToMap; DWORD desired_access; + if( !This->hfilemap ) + return FALSE; + if (lowoffset + PAGE_SIZE > This->filesize.s.LowPart) numBytesToMap = This->filesize.s.LowPart - lowoffset; else