Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit84f3a6f

Browse files
committed
Merge pull request#6666 from mdboom/limit-image-size
Guard against too-large figures
1 parent588b748 commit84f3a6f

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
@@ -9,6 +9,8 @@
99
importnumpyasnp
1010
fromnumpy.testingimportassert_array_almost_equal
1111

12+
fromnose.toolsimportassert_raises
13+
1214
frommatplotlib.imageimportimread
1315
frommatplotlib.backends.backend_aggimportFigureCanvasAggasFigureCanvas
1416
frommatplotlib.figureimportFigure
@@ -155,6 +157,13 @@ def test_long_path():
155157
fig.savefig(buff,format='png')
156158

157159

160+
@cleanup
161+
deftest_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
importnose
160169
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 =newRendererAgg(width, height, dpi))
181190

182191
return0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp