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 84f3a6f

Browse filesBrowse files
committed
Merge pull request #6666 from mdboom/limit-image-size
Guard against too-large figures
1 parent 588b748 commit 84f3a6f
Copy full SHA for 84f3a6f

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
@@ -9,6 +9,8 @@
99
import numpy as np
1010
from numpy.testing import assert_array_almost_equal
1111

12+
from nose.tools import assert_raises
13+
1214
from matplotlib.image import imread
1315
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
1416
from matplotlib.figure import Figure
@@ -155,6 +157,13 @@ def test_long_path():
155157
fig.savefig(buff, format='png')
156158

157159

160+
@cleanup
161+
def test_too_large_image():
162+
fig = plt.figure(figsize=(300, 1000))
163+
buff = io.BytesIO()
164+
assert_raises(ValueError, fig.savefig, buff)
165+
166+
158167
if __name__ == "__main__":
159168
import nose
160169
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.