Skip to content

Commit

Permalink
Added more robust sanity checking for CPIO results
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed Feb 23, 2018
1 parent f636501 commit a5bfe60
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/binwalk/plugins/cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,23 @@ def _get_file_name(self, description):
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):
Expand All @@ -99,7 +105,7 @@ def scan(self, result):
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
Expand Down

0 comments on commit a5bfe60

Please sign in to comment.