-Added a check to make verify that a section's calculated ending address does not overlap a subsequent section. If so cut it down to fit.
git-svn-id: http://pefile.googlecode.com/svn/trunk@116 8842bc4e-7134-0410-8230-5dc5194fb5c1
diff --git a/pefile.py b/pefile.py
index 35dcf49..8055bbb 100644
--- a/pefile.py
+++ b/pefile.py
@@ -1052,10 +1052,17 @@
size = self.Misc_VirtualSize
else:
size = max(self.SizeOfRawData, self.Misc_VirtualSize)
-
+
VirtualAddress_adj = self.pe.adjust_SectionAlignment( self.VirtualAddress,
self.pe.OPTIONAL_HEADER.SectionAlignment, self.pe.OPTIONAL_HEADER.FileAlignment )
+ # Check if there's any further section that will start before the
+ # calculated end for the current one, if so cut the current's size
+ # to fit in the range until the next one starts.
+ for s in self.pe.sections:
+ if s.VirtualAddress > self.VirtualAddress and VirtualAddress_adj + size > s.VirtualAddress:
+ size = s.VirtualAddress - VirtualAddress_adj
+
return VirtualAddress_adj <= rva < VirtualAddress_adj + size