Dmitry Timoshkov : ole32: Always initialize storage header before writing it.

Alexandre Julliard julliard at winehq.org
Fri Apr 2 16:10:11 CDT 2021


Module: wine
Branch: master
Commit: 6937e3ce7f05ada55c1df0646919cb29bfb39e4e
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=6937e3ce7f05ada55c1df0646919cb29bfb39e4e

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Wed Mar 31 10:45:36 2021 +0300

ole32: Always initialize storage header before writing it.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Esme Povirk <esme at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 44ff3a07a21..b05baddac98 100644
--- a/dlls/ole32/tests/storage32.c
+++ b/dlls/ole32/tests/storage32.c
@@ -3883,7 +3883,6 @@ static void test_custom_lockbytes(void)
     hr = IStorage_Commit(stg, 0);
     ok(hr==S_OK, "IStorage_Commit failed %x\n", hr);
 
-todo_wine
     ok(*(DWORD *)lockbytes->contents == 0xe011cfd0, "contents: %08x\n", *(DWORD *)lockbytes->contents);
 
     IStorage_Release(stg);




More information about the wine-cvs mailing list