@@ -708,8 +708,12 @@ _image_module::from_images(const Py::Tuple& args) {
708708
709709 args.verify_length (3 );
710710
711- size_t numrows = Py::Int (args[0 ]);
712- size_t numcols = Py::Int (args[1 ]);
711+ size_t numrows = (size_t )Py::Int (args[0 ]);
712+ size_t numcols = (size_t )Py::Int (args[1 ]);
713+
714+ if (numrows > 1 << 15 || numcols > 1 << 15 ) {
715+ throw Py::RuntimeError (" numrows and numcols must both be less than 32768" );
716+ }
713717
714718 Py::SeqBase<Py::Object> tups = args[2 ];
715719 size_t N = tups.length ();
@@ -1084,8 +1088,13 @@ _image_module::frombuffer(const Py::Tuple& args) {
10841088 args.verify_length (4 );
10851089
10861090 PyObject *bufin = new_reference_to (args[0 ]);
1087- int x = Py::Int (args[1 ]);
1088- int y = Py::Int (args[2 ]);
1091+ size_t x = Py::Int (args[1 ]);
1092+ size_t y = Py::Int (args[2 ]);
1093+
1094+ if (x > 1 << 15 || y > 1 << 15 ) {
1095+ throw Py::ValueError (" x and y must both be less than 32768" );
1096+ }
1097+
10891098 int isoutput = Py::Int (args[3 ]);
10901099
10911100 if (PyObject_CheckReadBuffer (bufin) != 1 )
@@ -1155,6 +1164,10 @@ _image_module::pcolor(const Py::Tuple& args) {
11551164 unsigned int cols = Py::Int (args[4 ]);
11561165 Py::Tuple bounds = args[5 ];
11571166
1167+ if (rows > 1 << 15 || cols > 1 << 15 ) {
1168+ throw Py::ValueError (" rows and cols must both be less than 32768" );
1169+ }
1170+
11581171 if (bounds.length () !=4 )
11591172 throw Py::TypeError (" Incorrect number of bounds (4 expected)" );
11601173 float x_min = Py::Float (bounds[0 ]);
@@ -1391,6 +1404,10 @@ _image_module::pcolor2(const Py::Tuple& args) {
13911404 Py::Tuple bounds = args[5 ];
13921405 Py::Object bgp = args[6 ];
13931406
1407+ if (rows > 1 << 15 || cols > 1 << 15 ) {
1408+ throw Py::ValueError (" rows and cols must both be less than 32768" );
1409+ }
1410+
13941411 if (bounds.length () !=4 )
13951412 throw Py::TypeError (" Incorrect number of bounds (4 expected)" );
13961413 double x_left = Py::Float (bounds[0 ]);
0 commit comments