Commit 4508cec8 by devttys0

Fixed bug in BlockFile where a specified length less than READ_BLOCK_SIZE caused…

Fixed bug in BlockFile where a specified length less than READ_BLOCK_SIZE caused total_read size to be invliad
parent 61a68f07
......@@ -385,31 +385,32 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
data = None
if self.total_read < self.length:
# Read in READ_BLOCK_SIZE plus MAX_TRAILING_SIZE bytes, but return a max dlen value
# of READ_BLOCK_SIZE. This ensures that there is a MAX_TRAILING_SIZE buffer at the
# end of the returned data in case a signature is found at or near data[dlen].
data = self._internal_read(self.READ_BLOCK_SIZE + self.MAX_TRAILING_SIZE)
# Read in self.READ_BLOCK_SIZE + self.MAX_TRAILING_SIZE, unless this exceeds self.length
rsize = self.READ_BLOCK_SIZE + self.MAX_TRAILING_SIZE
if (self.total_read + rsize) > self.length:
rsize = self.length - self.total_read
# Do the read. Must use self._internal_read so that the total_read value is untouched (we update this ourselves later)
data = self._internal_read(rsize)
if data and data is not None:
# Get the actual length of the read in data
dlen = len(data)
# Calculate how far back we need to seek to pick up at the self.READ_BLOCK_SIZE offset
seek_offset = dlen - self.READ_BLOCK_SIZE
# If rsize was less than self.READ_BLOCK_SIZE seek backwards zero bytes
if seek_offset < 0:
seek_offset = 0
# If we've read in more data than the scan length, truncate the dlen value
if (self.total_read + self.READ_BLOCK_SIZE) > self.length:
dlen = self.length - self.total_read
# If dlen is the expected rlen size, it should be set to READ_BLOCK_SIZE
elif dlen == (self.READ_BLOCK_SIZE + self.MAX_TRAILING_SIZE):
# Read in READ_BLOCK_SIZE plus MAX_TRAILING_SIZE bytes, but return a max dlen value
# Return a max dlen value of READ_BLOCK_SIZE. This ensures that there is a MAX_TRAILING_SIZE
# buffer at the end of the returned data in case a signature is found at or near data[READ_BLOCK_SIZE].
if dlen == (self.READ_BLOCK_SIZE + self.MAX_TRAILING_SIZE):
dlen = self.READ_BLOCK_SIZE
# Increment self.total_read to reflect the amount of data that has been read
# for processing (actual read size is larger of course, due to the MAX_TRAILING_SIZE
# buffer of data at the end of each block).
self.total_read += dlen
# Seek to the self.total_read offset so the next read can pick up where this one left off.
if seek_offset > 0:
self.seek(self.tell() - seek_offset)
return (data, dlen)
......
......@@ -74,6 +74,7 @@ class Result(object):
@offset - The file offset of the result.
@description - The result description, as displayed to the user.
@module - Name of the module that generated the result.
@file - The file object of the scanned file.
@valid - Set to True if the result if value, False if invalid.
@display - Set to True to display the result to the user, False to hide it.
......@@ -85,6 +86,7 @@ class Result(object):
'''
self.offset = 0
self.description = ''
self.module = ''
self.file = None
self.valid = True
self.display = True
......@@ -282,6 +284,8 @@ class Module(object):
if r is None:
r = Result(**kwargs)
r.module = self.__class__.__name__
# Any module that is reporting results, valid or not, should be marked as enabled
if not self.enabled:
self.enabled = True
......
......@@ -121,6 +121,7 @@ class Signature(Module):
# Set the absolute offset inside the target file
r.offset = block_start + candidate_offset + r.adjust
# Provide an instance of the current file object
r.file = fp
......
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