From d882f93fee2a36498e6f56461b9ce36fbb4c2df1 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sun, 22 May 2016 19:23:15 +0100 Subject: [PATCH] Move the length check, and require a non-zero length to protect is_valid. --- volatility/framework/layers/physical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/volatility/framework/layers/physical.py b/volatility/framework/layers/physical.py index 64709c436..2cb600f14 100644 --- a/volatility/framework/layers/physical.py +++ b/volatility/framework/layers/physical.py @@ -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: