Revision: 5733
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5733&view=rev
Author:   mdboom
Date:     2008-07-10 11:12:50 -0700 (Thu, 10 Jul 2008)

Log Message:
-----------
Add some range checking based on testing in Fusil.

Modified Paths:
--------------
    trunk/matplotlib/src/_backend_agg.cpp
    trunk/matplotlib/src/_image.cpp

Modified: trunk/matplotlib/src/_backend_agg.cpp
===================================================================
--- trunk/matplotlib/src/_backend_agg.cpp       2008-07-10 15:45:15 UTC (rev 
5732)
+++ trunk/matplotlib/src/_backend_agg.cpp       2008-07-10 18:12:50 UTC (rev 
5733)
@@ -1611,10 +1611,26 @@
   if ( kws.hasKey("debug") ) debug = Py::Int( kws["debug"] );
   else debug=0;
 
-  int width = Py::Int(args[0]);
-  int height = Py::Int(args[1]);
+  unsigned int width = (unsigned int)Py::Int(args[0]);
+  unsigned int height = (unsigned int)Py::Int(args[1]);
   double dpi = Py::Float(args[2]);
-  return Py::asObject(new RendererAgg(width, height, dpi, debug));
+
+  if (width > 1 << 15 || height > 1 << 15) {
+    throw Py::ValueError("width and height must each be below 32768");
+  }
+
+  if (dpi <= 0.0) {
+    throw Py::ValueError("dpi must be positive");
+  }
+
+  RendererAgg* renderer = NULL;
+  try {
+    renderer = new RendererAgg(width, height, dpi, debug);
+  } catch (std::bad_alloc) {
+    throw Py::RuntimeError("Could not allocate memory for image");
+  }
+
+  return Py::asObject(renderer);
 }
 
 

Modified: trunk/matplotlib/src/_image.cpp
===================================================================
--- trunk/matplotlib/src/_image.cpp     2008-07-10 15:45:15 UTC (rev 5732)
+++ trunk/matplotlib/src/_image.cpp     2008-07-10 18:12:50 UTC (rev 5733)
@@ -708,9 +708,13 @@
 
   args.verify_length(3);
 
-  size_t numrows = Py::Int(args[0]);
-  size_t numcols = Py::Int(args[1]);
+  size_t numrows = (size_t)Py::Int(args[0]);
+  size_t numcols = (size_t)Py::Int(args[1]);
 
+  if (numrows > 1 << 15 || numcols > 1 << 15) {
+    throw Py::RuntimeError("numrows and numcols must both be less than 32768");
+  }
+
   Py::SeqBase<Py::Object> tups = args[2];
   size_t N = tups.length();
 
@@ -1084,8 +1088,13 @@
   args.verify_length(4);
 
   PyObject *bufin = new_reference_to(args[0]);
-  int x = Py::Int(args[1]);
-  int y = Py::Int(args[2]);
+  size_t x = Py::Int(args[1]);
+  size_t y = Py::Int(args[2]);
+
+  if (x > 1 << 15 || y > 1 << 15) {
+    throw Py::ValueError("x and y must both be less than 32768");
+  }
+
   int isoutput = Py::Int(args[3]);
 
   if (PyObject_CheckReadBuffer(bufin) != 1)
@@ -1155,6 +1164,10 @@
   unsigned int cols = Py::Int(args[4]);
   Py::Tuple bounds = args[5];
 
+  if (rows > 1 << 15 || cols > 1 << 15) {
+    throw Py::ValueError("rows and cols must both be less than 32768");
+  }
+
   if (bounds.length() !=4)
       throw Py::TypeError("Incorrect number of bounds (4 expected)");
   float x_min = Py::Float(bounds[0]);
@@ -1391,6 +1404,10 @@
     Py::Tuple bounds = args[5];
     Py::Object bgp = args[6];
 
+    if (rows > 1 << 15 || cols > 1 << 15) {
+      throw Py::ValueError("rows and cols must both be less than 32768");
+    }
+
     if (bounds.length() !=4)
         throw Py::TypeError("Incorrect number of bounds (4 expected)");
     double x_left = Py::Float(bounds[0]);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to