From 7e607b9fb8bf8ff613db7020f44e128e132a3a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 17 Dec 2015 23:10:56 +0000 Subject: [PATCH] [DBGHELP][RTL] Fix usage of VirtualSize wrt. SizeOfRawData. CORE-10523 CORE-9548 #comment Please retest with revision >= 70390 svn path=/trunk/; revision=70390 --- reactos/dll/win32/dbghelp/compat.c | 15 +++++++-------- reactos/lib/rtl/image.c | 17 +++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/reactos/dll/win32/dbghelp/compat.c b/reactos/dll/win32/dbghelp/compat.c index 7a3a0534852..51a43453fa8 100644 --- a/reactos/dll/win32/dbghelp/compat.c +++ b/reactos/dll/win32/dbghelp/compat.c @@ -61,11 +61,11 @@ __RtlImageRvaToSection( while (Count--) { Va = SWAPD(Section->VirtualAddress); - if ((Va <= Rva) && - (Rva < Va + SWAPD(Section->Misc.VirtualSize))) + if ((Va <= Rva) && (Rva < Va + SWAPD(Section->SizeOfRawData))) return Section; Section++; } + return NULL; } @@ -83,9 +83,9 @@ __RtlImageRvaToVa if ((Section == NULL) || (Rva < SWAPD(Section->VirtualAddress)) || - (Rva >= SWAPD(Section->VirtualAddress) + SWAPD(Section->Misc.VirtualSize))) + (Rva >= SWAPD(Section->VirtualAddress) + SWAPD(Section->SizeOfRawData))) { - Section = RtlImageRvaToSection (NtHeader, BaseAddress, Rva); + Section = RtlImageRvaToSection(NtHeader, BaseAddress, Rva); if (Section == NULL) return NULL; @@ -93,9 +93,8 @@ __RtlImageRvaToVa *SectionHeader = Section; } - return (PVOID)((ULONG_PTR)BaseAddress + - Rva + - SWAPD(Section->PointerToRawData) - + return (PVOID)((ULONG_PTR)BaseAddress + Rva + + (ULONG_PTR)SWAPD(Section->PointerToRawData) - (ULONG_PTR)SWAPD(Section->VirtualAddress)); } @@ -132,7 +131,7 @@ __RtlImageDirectoryEntryToData( if (MappedAsImage || Va < SWAPD(NtHeader->OptionalHeader.SizeOfHeaders)) return (PVOID)((ULONG_PTR)BaseAddress + Va); - /* image mapped as ordinary file, we must find raw pointer */ + /* Image mapped as ordinary file, we must find raw pointer */ return RtlImageRvaToVa(NtHeader, BaseAddress, Va, NULL); } diff --git a/reactos/lib/rtl/image.c b/reactos/lib/rtl/image.c index 588fe249e9f..20ad99e5de9 100644 --- a/reactos/lib/rtl/image.c +++ b/reactos/lib/rtl/image.c @@ -301,11 +301,10 @@ RtlImageDirectoryEntryToData( if (MappedAsImage || Va < SWAPD(NtHeader->OptionalHeader.SizeOfHeaders)) return (PVOID)((ULONG_PTR)BaseAddress + Va); - /* image mapped as ordinary file, we must find raw pointer */ + /* Image mapped as ordinary file, we must find raw pointer */ return RtlImageRvaToVa(NtHeader, BaseAddress, Va, NULL); } - /* * @implemented */ @@ -326,15 +325,14 @@ RtlImageRvaToSection( while (Count--) { Va = SWAPD(Section->VirtualAddress); - if ((Va <= Rva) && - (Rva < Va + SWAPD(Section->Misc.VirtualSize))) + if ((Va <= Rva) && (Rva < Va + SWAPD(Section->SizeOfRawData))) return Section; Section++; } + return NULL; } - /* * @implemented */ @@ -353,9 +351,9 @@ RtlImageRvaToVa( if ((Section == NULL) || (Rva < SWAPD(Section->VirtualAddress)) || - (Rva >= SWAPD(Section->VirtualAddress) + SWAPD(Section->Misc.VirtualSize))) + (Rva >= SWAPD(Section->VirtualAddress) + SWAPD(Section->SizeOfRawData))) { - Section = RtlImageRvaToSection (NtHeader, BaseAddress, Rva); + Section = RtlImageRvaToSection(NtHeader, BaseAddress, Rva); if (Section == NULL) return NULL; @@ -363,9 +361,8 @@ RtlImageRvaToVa( *SectionHeader = Section; } - return (PVOID)((ULONG_PTR)BaseAddress + - Rva + - SWAPD(Section->PointerToRawData) - + return (PVOID)((ULONG_PTR)BaseAddress + Rva + + (ULONG_PTR)SWAPD(Section->PointerToRawData) - (ULONG_PTR)SWAPD(Section->VirtualAddress)); }