@@ -232,14 +232,16 @@ Image::color_conv(const Py::Tuple& args) {
232232 PyObject* py_buffer = PyBuffer_New (row_len * rowsOut);
233233 if (py_buffer ==NULL )
234234 throw Py::MemoryError (" Image::color_conv could not allocate memory" );
235- unsigned char * buf;
236- int buffer_len;
237- int ret = PyObject_AsWriteBuffer (py_buffer, (void **)&buf, &buffer_len);
235+
236+ void * buf;
237+ Py_ssize_t buffer_len;
238+ int ret = PyObject_AsWriteBuffer (py_buffer, &buf, &buffer_len);
238239 if (ret !=0 )
239240 throw Py::MemoryError (" Image::color_conv could not allocate memory" );
240241
241242 agg::rendering_buffer rtmp;
242- rtmp.attach (buf, colsOut, rowsOut, row_len);
243+ rtmp.attach (reinterpret_cast <unsigned char *>(buf), colsOut, rowsOut,
244+ row_len);
243245
244246 switch (format) {
245247 case 0 :
@@ -869,7 +871,8 @@ _image_module::readpng(const Py::Tuple& args) {
869871 if (!fp)
870872 throw Py::RuntimeError (Printf (" _image_module::readpng could not open PNG file %s for reading" , fname.c_str ()).str ());
871873
872- fread (header, 1 , 8 , fp);
874+ if (fread (header, 1 , 8 , fp) != 8 )
875+ throw Py::RuntimeError (" _image_module::readpng: error reading PNG header" );
873876 if (png_sig_cmp (header, 0 , 8 ))
874877 throw Py::RuntimeError (" _image_module::readpng: file not recognized as a PNG file" );
875878
0 commit comments