Skip to content

Commit 5b89c9c

Browse files
committed
Fix creation of AGG images bigger than 1024**3 pixels
Various buffer size calculations were overflowing, because C is awesome. Simple reproduction case: ```python import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(463, 232), dpi=100) fig.savefig('big.png') ``` (A size of 462x232 is just *under* the gigapixel threshold.)
1 parent a8f52d9 commit 5b89c9c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/_backend_agg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
2929
: width(width),
3030
height(height),
3131
dpi(dpi),
32-
NUMBYTES(width * height * 4),
32+
NUMBYTES((size_t) width * (size_t) height * 4),
3333
pixBuffer(NULL),
3434
renderingBuffer(),
3535
alphaBuffer(NULL),

src/_backend_agg_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int PyBufferRegion_get_buffer(PyBufferRegion *self, Py_buffer *buf, int flags)
9595
Py_INCREF(self);
9696
buf->obj = (PyObject *)self;
9797
buf->buf = self->x->get_data();
98-
buf->len = self->x->get_width() * self->x->get_height() * 4;
98+
buf->len = (long) self->x->get_width() * (long) self->x->get_height() * 4;
9999
buf->readonly = 0;
100100
buf->format = (char *)"B";
101101
buf->ndim = 3;
@@ -531,7 +531,7 @@ int PyRendererAgg_get_buffer(PyRendererAgg *self, Py_buffer *buf, int flags)
531531
Py_INCREF(self);
532532
buf->obj = (PyObject *)self;
533533
buf->buf = self->x->pixBuffer;
534-
buf->len = self->x->get_width() * self->x->get_height() * 4;
534+
buf->len = (long) self->x->get_width() * (long) self->x->get_height() * 4;
535535
buf->readonly = 0;
536536
buf->format = (char *)"B";
537537
buf->ndim = 3;

0 commit comments

Comments
 (0)