about summary refs log tree commit diff stats
path: root/miasm2/core/bin_stream.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2019-02-04 16:13:58 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2019-02-04 17:24:37 +0100
commit45a3bab9ee337e36437e4be207bb8387ef2294f3 (patch)
tree15e28c0ca26c08a335e60a32e6d5be442294d8a8 /miasm2/core/bin_stream.py
parent7af9269b2df2898ce50bd03f0d9efc8bd175aa7d (diff)
downloadmiasm-45a3bab9ee337e36437e4be207bb8387ef2294f3.tar.gz
miasm-45a3bab9ee337e36437e4be207bb8387ef2294f3.zip
bin_stream: check negative offset
Diffstat (limited to 'miasm2/core/bin_stream.py')
-rw-r--r--miasm2/core/bin_stream.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/miasm2/core/bin_stream.py b/miasm2/core/bin_stream.py
index 8bd59467..1dada90f 100644
--- a/miasm2/core/bin_stream.py
+++ b/miasm2/core/bin_stream.py
@@ -170,12 +170,16 @@ class bin_stream_str(bin_stream):
     def _getbytes(self, start, l=1):
         if start + l + self.shift > self.l:
             raise IOError("not enough bytes in str")
+        if start + self.shift < 0:
+            raise IOError("Negative offset")
 
         return super(bin_stream_str, self)._getbytes(start + self.shift, l)
 
     def readbs(self, l=1):
         if self.offset + l + self.shift > self.l:
             raise IOError("not enough bytes in str")
+        if self.offset + self.shift < 0:
+            raise IOError("Negative offset")
         self.offset += l
         return self.bin[self.offset - l + self.shift:self.offset + self.shift]
 
@@ -210,6 +214,8 @@ class bin_stream_file(bin_stream):
     def readbs(self, l=1):
         if self.offset + l + self.shift > self.l:
             raise IOError("not enough bytes in file")
+        if self.offset + self.shift < 0:
+            raise IOError("Negative offset")
         return self.bin.read(l)
 
     def __str__(self):
@@ -236,6 +242,8 @@ class bin_stream_container(bin_stream):
     def readbs(self, l=1):
         if self.offset + l > self.l:
             raise IOError("not enough bytes")
+        if self.offset < 0:
+            raise IOError("Negative offset")
         self.offset += l
         return self.bin.virt.get(self.offset - l, self.offset)