Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6effa8

Browse filesBrowse files
authored
Merge pull request #6666 from mdboom/limit-image-size
Guard against too-large figures
2 parents 31be20b + 604e06e commit f6effa8
Copy full SHA for f6effa8

File tree

Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed

‎lib/matplotlib/tests/test_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_agg.py
+9Lines 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

Copy file name to clipboardExpand all lines: src/_backend_agg_wrapper.cpp
+9Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.