Don't allow more dimensions than buffer_max_dims
authorMark Florisson <markflorisson88@gmail.com>
Sun, 6 May 2012 17:29:53 +0000 (18:29 +0100)
committerMark Florisson <markflorisson88@gmail.com>
Fri, 11 May 2012 10:48:57 +0000 (11:48 +0100)
Cython/Compiler/ExprNodes.py
Cython/Compiler/MemoryView.py
Cython/Compiler/Nodes.py
tests/errors/memview_declarations.pyx

index 093b99a..8162464 100755 (executable)
@@ -2644,6 +2644,11 @@ class IndexNode(ExprNode):
             self.index = None
             self.is_temp = True
             self.use_managed_ref = True
+
+            if not MemoryView.validate_axes(self.pos, axes):
+                self.type = error_type
+                return
+
             self.type = PyrexTypes.MemoryViewSliceType(
                             self.base.type.dtype, axes)
 
index 135a1f3..bd5ff0f 100644 (file)
@@ -723,6 +723,14 @@ def get_axes_specs(env, axes):
 
     return axes_specs
 
+def validate_axes(pos, axes):
+    if len(axes) >= Options.buffer_max_dims:
+        error(pos, "More dimensions than the maximum number"
+                   " of buffer dimensions were used.")
+        return False
+
+    return True
+
 def all(it):
     for item in it:
         if not item:
index 03a7232..b7070bb 100644 (file)
@@ -883,10 +883,13 @@ class MemoryViewSliceTypeNode(CBaseTypeNode):
             self.type = PyrexTypes.ErrorType()
             return self.type
 
-        MemoryView.validate_memslice_dtype(self.pos, base_type)
-        self.type = PyrexTypes.MemoryViewSliceType(base_type, axes_specs)
+        if not MemoryView.validate_axes(self.pos, axes_specs):
+            self.type = error_type
+        else:
+            MemoryView.validate_memslice_dtype(self.pos, base_type)
+            self.type = PyrexTypes.MemoryViewSliceType(base_type, axes_specs)
+            self.use_memview_utilities(env)
 
-        self.use_memview_utilities(env)
         return self.type
 
     def use_memview_utilities(self, env):
index 771dfa9..b51caab 100644 (file)
@@ -54,8 +54,15 @@ cdef struct Invalid:
 cdef Valid[:] validslice
 cdef Invalid[:] invalidslice
 
+cdef int[:, :, :, :] four_D
+four_D[None, None, None, None]
+four_D[None, None, None, None, None]
+
+cdef int[:, :, :, :, :, :, :, :] eight_D = object()
+
 # These are VALID
 cdef int[::view.indirect_contiguous, ::view.contiguous] a9
+four_D[None, None, None]
 
 _ERRORS = u'''
 11:25: Cannot specify an array that is both C and Fortran contiguous.
@@ -79,4 +86,7 @@ _ERRORS = u'''
 46:35: Can only create cython.array from pointer or array
 47:24: Cannot assign type 'double' to 'Py_ssize_t'
 55:13: Invalid base type for memoryview slice: Invalid
+58:6: More dimensions than the maximum number of buffer dimensions were used.
+59:6: More dimensions than the maximum number of buffer dimensions were used.
+61:9: More dimensions than the maximum number of buffer dimensions were used.
 '''