[PATCH 2/2] ole32: Always initialize storage header before writing it.

Dmitry Timoshkov dmitry at baikal.ru
Tue Mar 30 09:41:41 CDT 2021


Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
 dlls/ole32/storage32.c       | 33 ++++-----------------------------
 dlls/ole32/tests/storage32.c |  1 -
 2 files changed, 4 insertions(+), 30 deletions(-)

diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c
index 3d372af83f5..980b6c8d9f6 100644
--- a/dlls/ole32/storage32.c
+++ b/dlls/ole32/storage32.c
@@ -3016,20 +3016,10 @@ static void StorageImpl_SaveFileHeader(
 {
   BYTE   headerBigBlock[HEADER_SIZE];
   int    index;
-  HRESULT hr;
   ULARGE_INTEGER offset;
-  DWORD bytes_read, bytes_written;
+  DWORD bytes_written;
   DWORD major_version, dirsectorcount;
 
-  /*
-   * Get a pointer to the big block of data containing the header.
-   */
-  offset.u.HighPart = 0;
-  offset.u.LowPart = 0;
-  hr = StorageImpl_ReadAt(This, offset, headerBigBlock, HEADER_SIZE, &bytes_read);
-  if (SUCCEEDED(hr) && bytes_read != HEADER_SIZE)
-    hr = STG_E_FILENOTFOUND;
-
   if (This->bigBlockSizeBits == 0x9)
     major_version = 3;
   else if (This->bigBlockSizeBits == 0xc)
@@ -3040,21 +3030,8 @@ static void StorageImpl_SaveFileHeader(
     major_version = 4;
   }
 
-  /*
-   * If the block read failed, the file is probably new.
-   */
-  if (FAILED(hr))
-  {
-    /*
-     * Initialize for all unknown fields.
-     */
-    memset(headerBigBlock, 0, HEADER_SIZE);
-
-    /*
-     * Initialize the magic number.
-     */
-    memcpy(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic));
-  }
+  memset(headerBigBlock, 0, HEADER_SIZE);
+  memcpy(headerBigBlock, STORAGE_magic, sizeof(STORAGE_magic));
 
   /*
    * Write the information to the header.
@@ -3150,9 +3127,7 @@ static void StorageImpl_SaveFileHeader(
       (This->bigBlockDepotStart[index]));
   }
 
-  /*
-   * Write the big block back to the file.
-   */
+  offset.QuadPart = 0;
   StorageImpl_WriteAt(This, offset, headerBigBlock, HEADER_SIZE, &bytes_written);
 }
 
diff --git a/dlls/ole32/tests/storage32.c b/dlls/ole32/tests/storage32.c
index da2e411eea4..3dc63ed1b12 100644
--- a/dlls/ole32/tests/storage32.c
+++ b/dlls/ole32/tests/storage32.c
@@ -4060,7 +4060,6 @@ todo_wine
     IStorage_Release(stg);
 
     p = GlobalLock(This->mem);
-todo_wine
     ok(*p == 0xe011cfd0, "got %#x\n", *p);
     GlobalUnlock(This->mem);
 
-- 
2.30.2




More information about the wine-devel mailing list