From 60cc4361b69d5e520f797527510e89d71eaa4fa6 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Sat, 31 May 2014 21:16:08 -1000 Subject: [PATCH] Image: handle images with zero columns or rows. Two methods in the _image extension module now raise an exception if the number of rows or columns is zero; previously they could segfault. A particular circumstance that can cause this (setting xlim completely outside the image extent) is handled directly in the image module without raising an exception. Closes #3091. --- lib/matplotlib/image.py | 2 ++ src/_image.cpp | 6 +++--- src/_image.h | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index f2c471a71f89..0f6cd2750ee8 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -327,6 +327,8 @@ def _draw_unsampled_image(self, renderer, gc): im.reset_matrix() numrows, numcols = im.get_size() + if numrows <= 0 or numcols <= 0: + return im.resize(numcols, numrows) # just to create im.bufOut that # is required by backends. There # may be better solution -JJL diff --git a/src/_image.cpp b/src/_image.cpp index b85cdf2af9f6..b1c59e9674ba 100644 --- a/src/_image.cpp +++ b/src/_image.cpp @@ -374,10 +374,10 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs) int numcols = Py::Int(args[0]); int numrows = Py::Int(args[1]); - if (numcols < 0 || numrows < 0) + if (numcols <= 0 || numrows <= 0) { - throw Py::RuntimeError( - "Width and height must have non-negative values"); + throw Py::RuntimeError( + "Width and height must have positive values"); } colsOut = numcols; diff --git a/src/_image.h b/src/_image.h index 425bc2462ff3..aa0de94174cd 100644 --- a/src/_image.h +++ b/src/_image.h @@ -45,6 +45,12 @@ class Image : public Py::PythonExtension inline Py::Object flipud_out(const Py::Tuple& args) { args.verify_length(0); + if (colsOut <= 0 || rowsOut <= 0) + { + throw Py::RuntimeError( + "Width and height must have positive values"); + } + int stride = rbufOut->stride(); //std::cout << "flip before: " << rbufOut->stride() << std::endl; rbufOut->attach(bufferOut, colsOut, rowsOut, -stride); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy