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

Guard against too-large figures #6666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2016
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
Guard against too-large figures
  • Loading branch information
mdboom committed Jun 29, 2016
commit 604e06eaa82bb04f33f19961ed871525dd5419b9
9 changes: 9 additions & 0 deletions 9 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 9 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.