Move the length check, and require a non-zero length to protect is_valid.

This commit is contained in:
Mike Auty
2016-05-22 19:23:15 +01:00
parent 9faa13820a
commit d882f93fee
+2 -2
View File
@@ -80,6 +80,8 @@ class FileLayer(interfaces.layers.DataLayerInterface):
def is_valid(self, offset, length = 1):
"""Returns whether the offset is valid or not"""
if length <= 0:
raise TypeError("Length must be positive")
return (self.minimum_address <= offset <= self.maximum_address and
self.minimum_address <= offset + length - 1 <= self.maximum_address)
@@ -87,8 +89,6 @@ class FileLayer(interfaces.layers.DataLayerInterface):
"""Reads from the file at offset for length"""
if not self.is_valid(offset, length):
raise exceptions.InvalidAddressException("Offset outside of the " + self.name + " file boundaries")
if length < 0:
raise TypeError("Length must be positive")
self._file.seek(offset)
data = self._file.read(length)
if len(data) < length: