-Added additional check in the resources string parser to avoid processing strings of length zero
git-svn-id: http://pefile.googlecode.com/svn/trunk@99 8842bc4e-7134-0410-8230-5dc5194fb5c1
diff --git a/pefile.py b/pefile.py
index 81c3a94..03afa4e 100644
--- a/pefile.py
+++ b/pefile.py
@@ -524,6 +524,7 @@
#
def parse_strings(data, counter, l):
i = 0
+ error_count = 0
while i < len(data):
data_slice = data[i:i + 2]
@@ -532,11 +533,14 @@
len_ = struct.unpack("<h", data_slice)[0]
i += 2
- if len_ != 0 and len_ <= len(data):
+ if len_ != 0 and 0 <= len_*2 <= len(data):
try:
l[counter] = data[i: i + len_ * 2].decode('utf-16')
except UnicodeDecodeError:
+ error_count += 1
pass
+ if error_count >= 3:
+ break
i += len_ * 2
counter += 1