[PATCH 2/2] imagehlp: Fix checksum calculation for odd sizes.
From: Michael Müller <michael(a)fds-team.de> Signed-off-by: Vijay Kiran Kamuju <infyquest(a)gmail.com> --- dlls/imagehlp/modify.c | 39 ++++++++++++++++----------------- dlls/imagehlp/tests/integrity.c | 2 +- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/dlls/imagehlp/modify.c b/dlls/imagehlp/modify.c index aa29ca7a02..2a0214bacc 100644 --- a/dlls/imagehlp/modify.c +++ b/dlls/imagehlp/modify.c @@ -60,26 +60,25 @@ BOOL WINAPI BindImageEx( /*********************************************************************** * CheckSum (internal) */ -static WORD CalcCheckSum( - DWORD StartValue, LPVOID BaseAddress, DWORD WordCount) +static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD ByteCount) { - LPWORD Ptr; - DWORD Sum; - DWORD i; - - Sum = StartValue; - Ptr = (LPWORD)BaseAddress; - for (i = 0; i < WordCount; i++) - { - Sum += *Ptr; - if (HIWORD(Sum) != 0) - { - Sum = LOWORD(Sum) + HIWORD(Sum); - } - Ptr++; - } - - return (WORD)(LOWORD(Sum) + HIWORD(Sum)); + LPWORD Ptr; + DWORD Sum, i; + + Sum = StartValue; + Ptr = (LPWORD)BaseAddress; + for (i = ByteCount; i > 1; i -= 2) + { + Sum += *Ptr; + if (HIWORD(Sum) != 0) + Sum = LOWORD(Sum) + HIWORD(Sum); + Ptr++; + } + + if (i == 1) + Sum += *(BYTE *)Ptr; + + return (WORD)(LOWORD(Sum) + HIWORD(Sum)); } @@ -102,7 +101,7 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile( BaseAddress, FileLength, HeaderSum, CheckSum ); - CalcSum = (DWORD)CalcCheckSum(0, BaseAddress, (FileLength + 1) / sizeof(WORD)); + CalcSum = (DWORD)CalcCheckSum(0, BaseAddress, FileLength); __TRY { diff --git a/dlls/imagehlp/tests/integrity.c b/dlls/imagehlp/tests/integrity.c index b62b37cd4b..fff39127cf 100644 --- a/dlls/imagehlp/tests/integrity.c +++ b/dlls/imagehlp/tests/integrity.c @@ -350,7 +350,7 @@ static void test_pe_checksum(void) ret = pCheckSumMappedFile(buffer, 11, &checksum_orig, &checksum_new); ok(ret == NULL, "Expected NULL, got %p\n", ret); ok(checksum_orig == 0, "Expected 0, got %x\n", checksum_orig); - todo_wine ok(checksum_new == 0xaad7, "Expected 0xaad7, got %x\n", checksum_new); + ok(checksum_new == 0xaad7, "Expected 0xaad7, got %x\n", checksum_new); /* test checksum of PE module */ memset(buffer, 0x22, sizeof(buffer)); -- 2.21.0
Hi, While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=49790 Your paranoid android. === debian9 (32 bit report) === imagehlp: Unhandled exception: page fault on read access to 0x7edb1000 in 32-bit code (0x7ed94350). Report errors: imagehlp:integrity crashed (c0000005) === debian9 (32 bit French report) === imagehlp: Unhandled exception: page fault on read access to 0x7edbb000 in 32-bit code (0x7ed9e350). Report errors: imagehlp:integrity crashed (c0000005) === debian9 (32 bit Japanese:Japan report) === imagehlp: Unhandled exception: page fault on read access to 0x7edc9000 in 32-bit code (0x7edac350). Report errors: imagehlp:integrity crashed (c0000005) === debian9 (32 bit Chinese:China report) === imagehlp: Unhandled exception: page fault on read access to 0x7edbb000 in 32-bit code (0x7ed9e350). Report errors: imagehlp:integrity crashed (c0000005) === debian9b (32 bit WoW report) === imagehlp: Unhandled exception: page fault on read access to 0x7edc8000 in 32-bit code (0xf73a3350). Report errors: imagehlp:integrity crashed (c0000005)
participants (2)
-
Marvin -
Vijay Kiran Kamuju