From 5242bde5187de1198c1b9db24550eaaee783cd77 Mon Sep 17 00:00:00 2001 From: Robert van Herk Date: Thu, 29 Mar 2012 17:36:13 +0200 Subject: =?UTF-8?q?In=20Wine,=20MsiGetFileHashW=20fails=20on=20empty=20files?= =?UTF-8?q?.=20However,=20in=20Windows=20it=0Ajust=20generates=20a=200=20has?= =?UTF-8?q?h.=0AA=20patch=20+=20test=20is=20provided.=0A modified:=20=20=20d?= =?UTF-8?q?lls/msi/msi.c=0A modified:=20=20=20dlls/msi/tests/msi.c?= --- dlls/msi/msi.c | 40 ++++++++++++++++++++++++---------------- dlls/msi/tests/msi.c | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 53ae641..01a5568 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -4014,24 +4014,32 @@ UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions, } length = GetFileSize( handle, NULL ); - mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL ); - if (mapping) + if (length) { - p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length ); - if (p) - { - MD5_CTX ctx; - - MD5Init( &ctx ); - MD5Update( &ctx, p, length ); - MD5Final( &ctx ); - UnmapViewOfFile( p ); - - memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData ); - r = ERROR_SUCCESS; - } - CloseHandle( mapping ); + mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL ); + if (mapping) + { + p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length ); + if (p) + { + MD5_CTX ctx; + + MD5Init( &ctx ); + MD5Update( &ctx, p, length ); + MD5Final( &ctx ); + UnmapViewOfFile( p ); + + memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData ); + r = ERROR_SUCCESS; + } + CloseHandle( mapping ); + } + } else { + /* Empty file -> set hash to 0 */ + memset( pHash->dwData, 0, sizeof pHash->dwData ); + r = ERROR_SUCCESS; } + CloseHandle( handle ); return r; diff --git a/dlls/msi/tests/msi.c b/dlls/msi/tests/msi.c index aaf1f42..19e3218 100644 --- a/dlls/msi/tests/msi.c +++ b/dlls/msi/tests/msi.c @@ -493,6 +493,44 @@ static void test_MsiGetFileHash(void) } } +static void test_MsiGetFileHashForEmptyFile(void) { + char path[MAX_PATH]; + MSIFILEHASHINFO hi; + char file[MAX_PATH]; + UINT res; + + /* Create empty temp file */ + GetTempPath( + MAX_PATH, + path + ); + res = GetTempFileName( + path, + "tmp", + 0, + file + ); + + ok (res, "Could not create temporary file.\n"); + + if (res) { + /*Get the hash of the empty temp file */ + + hi.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO); + /* Fill hash with some random data */ + hi.dwData[0] = 15; + hi.dwData[1] = 25; + hi.dwData[2] = 35; + hi.dwData[3] = 45; + + res = MsiGetFileHash(file, 0, &hi); + ok(res == ERROR_SUCCESS, "MsiGetFileHash failed for empty file.\n"); + ok(hi.dwData[0] == 0 && hi.dwData[1] == 0 && hi.dwData[2] == 0 && hi.dwData[3] == 0, + "MsiGetFileHash of emptyfile should generate hashcode 0." + ); + } +} + /* copied from dlls/msi/registry.c */ static BOOL squash_guid(LPCWSTR in, LPWSTR out) { @@ -11964,7 +12002,8 @@ START_TEST(msi) test_null(); test_getcomponentpath(); test_MsiGetFileHash(); - + test_MsiGetFileHashForEmptyFile(); + if (!pConvertSidToStringSidA) win_skip("ConvertSidToStringSidA not implemented\n"); else -- 1.7.7.6