From 6937e3ce7f05ada55c1df0646919cb29bfb39e4e Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Wed, 31 Mar 2021 10:45:36 +0300 Subject: [PATCH] ole32: Always initialize storage header before writing it. Signed-off-by: Dmitry Timoshkov Signed-off-by: Esme Povirk Signed-off-by: Alexandre Julliard --- 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);