8000 Merge pull request #3102 from efiring/image_segfault · matplotlib/matplotlib@3f63888 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f63888

Browse files
committed
Merge pull request #3102 from efiring/image_segfault
Image: handle images with zero columns or rows.
2 parents e2c5918 + 60cc436 commit 3f63888

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ def _draw_unsampled_image(self, renderer, gc):
327327
im.reset_matrix()
328328
numrows, numcols = im.get_size()
329329

330+
if numrows <= 0 or numcols <= 0:
331+
return
330332
im.resize(numcols, numrows) # just to create im.bufOut that
331333
# is required by backends. There
332334
# may be better solution -JJL
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs)
374374
int numcols = Py::Int(args[0]);
375375
int numrows = Py::Int(args[1]);
376376

377-
if (numcols < 0 || numrows < 0)
377+
if (numcols <= 0 || numrows <= 0)
378378
{
379-
throw Py::RuntimeError(
380-
"Width and height must have non-negative values");
379+
throw Py::RuntimeError(
380+
"Width and height must have positive values");
381381
}
382382

383383
colsOut = numcols;
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class Image : public Py::PythonExtension<Image>
4545
inline Py::Object flipud_out(const Py::Tuple& args)
4646
{
4747
args.verify_length(0);
48+
if (colsOut <= 0 || rowsOut <= 0)
49+
{
50+
throw Py::RuntimeError(
51+
"Width and height must have positive values");
52+
}
53+
4854
int stride = rbufOut->stride();
4955
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
5056
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);