Commit a5bfe605 by devttys0

Added more robust sanity checking for CPIO results

parent f636501d
......@@ -72,17 +72,23 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
return name
def _get_file_name_length(self, description):
length = 0
length = None
if 'file name length: "' in description:
length_string = description.split('file name length: "')[1].split('"')[0]
length = int(length_string, 0)
try:
length = int(length_string, 0)
except ValueError:
pass
return length
def _get_file_size(self, description):
size = 0
size = None
if 'file size: "' in description:
size_string = description.split('file size: "')[1].split('"')[0]
size = int(size_string, 0)
try:
size = int(size_string, 0)
except ValueError:
pass
return size
def scan(self, result):
......@@ -99,7 +105,7 @@ class CPIOPlugin(binwalk.core.plugin.Plugin):
file_name_length = self._get_file_name_length(result.description)
# The +1 is to include the terminating NULL byte
if file_name_length != len(file_name)+1:
if None in [file_size, file_name_length] or file_name_length != len(file_name)+1:
# If the reported length of the file name doesn't match the actual
# file name length, treat this as a false positive result.
result.valid = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment