X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import numpy as np
from numpy.testing import assert_array_almost_equal

from nose.tools import assert_raises

from matplotlib.image import imread
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
Expand Down Expand Up @@ -290,6 +292,13 @@ def process_image(self, padded_src, dpi):
ax.yaxis.set_visible(False)


@cleanup
def test_too_large_image():
fig = plt.figure(figsize=(300, 1000))
buff = io.BytesIO()
assert_raises(ValueError, fig.savefig, buff)


if __name__ == "__main__":
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
9 changes: 9 additions & 0 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ static int PyRendererAgg_init(PyRendererAgg *self, PyObject *args, PyObject *kwd
return -1;
}

if (width >= 1 << 16 || height >= 1 << 16) {
PyErr_Format(
PyExc_ValueError,
"Image size of %dx%d pixels is too large. "
"It must be less than 2^16 in each direction.",
width, height);
return -1;
}

CALL_CPP_INIT("RendererAgg", self->x = new RendererAgg(width, height, dpi))

return 0;
Expand Down
X Tutup