Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 604e06e

Browse files
committed
Guard against too-large figures
1 parent 31be20b commit 604e06e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/matplotlib/tests/test_agg.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import numpy as np
1212
from numpy.testing import assert_array_almost_equal
1313

14+
from nose.tools import assert_raises
15+
1416
from matplotlib.image import imread
1517
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
1618
from matplotlib.figure import Figure
@@ -290,6 +292,13 @@ def process_image(self, padded_src, dpi):
290292
ax.yaxis.set_visible(False)
291293

292294

295+
@cleanup
296+
def test_too_large_image():
297+
fig = plt.figure(figsize=(300, 1000))
298+
buff = io.BytesIO()
299+
assert_raises(ValueError, fig.savefig, buff)
300+
301+
293302
if __name__ == "__main__":
294303
import nose
295304
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

src/_backend_agg_wrapper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ static int PyRendererAgg_init(PyRendererAgg *self, PyObject *args, PyObject *kwd
177177
return -1;
178178
}
179179

180+
if (width >= 1 << 16 || height >= 1 << 16) {
181+
PyErr_Format(
182+
PyExc_ValueError,
183+
"Image size of %dx%d pixels is too large. "
184+
"It must be less than 2^16 in each direction.",
185+
width, height);
186+
return -1;
187+
}
188+
180189
CALL_CPP_INIT("RendererAgg", self->x = new RendererAgg(width, height, dpi))
181190

182191
return 0;

0 commit comments

Comments
 (0)