Robert van Herk : msi: Fixed MsiGetFileHashW for empty files.
Alexandre Julliard
julliard at winehq.org
Fri Apr 6 14:43:26 CDT 2012
Module: wine
Branch: master
Commit: f87c4a36ddc1a32af392e45b0af1feff8c388852
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f87c4a36ddc1a32af392e45b0af1feff8c388852
Author: Robert van Herk <mijnspamboxje at hotmail.com>
Date: Thu Apr 5 13:08:08 2012 +0200
msi: Fixed MsiGetFileHashW for empty files.
---
dlls/msi/msi.c | 34 ++++++++++++++++++++++------------
dlls/msi/tests/msi.c | 6 ++++++
2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c
index 53ae641..4d18265 100644
--- a/dlls/msi/msi.c
+++ b/dlls/msi/msi.c
@@ -4014,24 +4014,34 @@ 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)
+ mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
+ if (mapping)
{
- MD5_CTX ctx;
+ p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
+ if (p)
+ {
+ MD5_CTX ctx;
- MD5Init( &ctx );
- MD5Update( &ctx, p, length );
- MD5Final( &ctx );
- UnmapViewOfFile( p );
+ MD5Init( &ctx );
+ MD5Update( &ctx, p, length );
+ MD5Final( &ctx );
+ UnmapViewOfFile( p );
- memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
- r = ERROR_SUCCESS;
+ memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
+ r = ERROR_SUCCESS;
+ }
+ CloseHandle( mapping );
}
- 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 f12af78..8768d2a 100644
--- a/dlls/msi/tests/msi.c
+++ b/dlls/msi/tests/msi.c
@@ -417,6 +417,12 @@ static const struct
MSIFILEHASHINFO hash;
} hash_data[] =
{
+ { "", 0,
+ { HASHSIZE,
+ { 0, 0, 0, 0 },
+ },
+ },
+
{ "abc", 0,
{ HASHSIZE,
{ 0x98500190, 0xb04fd23c, 0x7d3f96d6, 0x727fe128 },
More information about the wine-cvs
mailing list