Skip to content

Change hard coded image size limits from (32768, 32768) pixels to (INT_MAX, INT_MAX) #3451

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

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 4 additions & 2 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2518,9 +2518,11 @@ Py::Object _backend_agg_module::new_renderer(const Py::Tuple &args,
unsigned int height = (int)Py::Int(args[1]);
double dpi = Py::Float(args[2]);

if (width > 1 << 15 || height > 1 << 15)
char msg [256];
if (width > INT_MAX || height > INT_MAX)
{
throw Py::ValueError("width and height must each be below 32768");
sprintf(msg, "width and height must each be below %d", INT_MAX);
throw Py::ValueError(msg);
}

if (dpi <= 0.0)
Expand Down
12 changes: 9 additions & 3 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef __BACKEND_AGG_H
#define __BACKEND_AGG_H
#include <utility>
#include <climits>
#include "CXX/Extensions.hxx"

#include "agg_arrowhead.h"
Expand Down Expand Up @@ -59,10 +60,15 @@ typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_aa;
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_bin;
typedef agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> rasterizer;

typedef agg::scanline_p8 scanline_p8;
typedef agg::scanline_bin scanline_bin;
// typedef agg::scanline_p8 scanline_p8; // 16 bits display rendering
// typedef agg::scanline_bin scanline_bin; // 16 bits display rendering
typedef agg::scanline32_p8 scanline_p8; // 32 bits display rendering
typedef agg::scanline32_bin scanline_bin; // 32 bits display rendering

typedef agg::amask_no_clip_gray8 alpha_mask_type;
typedef agg::scanline_u8_am<alpha_mask_type> scanline_am;

// typedef agg::scanline_u8_am<alpha_mask_type> scanline_am; // 16 bits display rendering
typedef agg::scanline32_u8_am<alpha_mask_type> scanline_am; // 32 bits display rendering

typedef agg::renderer_base<agg::pixfmt_gray8> renderer_base_alpha_mask_type;
typedef agg::renderer_scanline_aa_solid<renderer_base_alpha_mask_type> renderer_alpha_mask_type;
Expand Down
26 changes: 18 additions & 8 deletions src/_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,11 @@ _image_module::from_images(const Py::Tuple& args)
size_t numrows = (long)Py::Int(args[0]);
size_t numcols = (long)Py::Int(args[1]);

if (numrows >= 32768 || numcols >= 32768)
char msg [256];
if (numrows >= INT_MAX || numcols >= INT_MAX)
{
throw Py::RuntimeError("numrows and numcols must both be less than 32768");
sprintf(msg, "numrows and numcols must both be less than %d", INT_MAX);
throw Py::ValueError(msg);
}

Py::SeqBase<Py::Object> tups = args[2];
Expand Down Expand Up @@ -1268,9 +1270,11 @@ _image_module::frombuffer(const Py::Tuple& args)
size_t x = (long)Py::Int(args[1]);
size_t y = (long)Py::Int(args[2]);

if (x >= 32768 || y >= 32768)
char msg [256];
if (x >= INT_MAX || y >= INT_MAX)
{
throw Py::ValueError("x and y must both be less than 32768");
sprintf(msg, "numrows and numcols must both be less than %d", INT_MAX);
throw Py::ValueError(msg);
}

int isoutput = Py::Int(args[3]);
Expand Down Expand Up @@ -1576,9 +1580,11 @@ _image_module::pcolor(const Py::Tuple& args)
Py::Tuple bounds = args[5];
unsigned int interpolation = (unsigned long)Py::Int(args[6]);

if (rows >= 32768 || cols >= 32768)
char msg [256];
if (rows >= INT_MAX || cols >= INT_MAX)
{
throw Py::ValueError("rows and cols must both be less than 32768");
sprintf(msg, "rows and cols must both be less than %d", INT_MAX);
throw Py::ValueError(msg);
}

if (bounds.length() != 4)
Expand Down Expand Up @@ -1822,11 +1828,15 @@ _image_module::pcolor2(const Py::Tuple& args)
Py::Tuple bounds = args[5];
Py::Object bgp = args[6];

if (rows >= 32768 || cols >= 32768)
char msg [256];
if (rows >= INT_MAX || cols >= INT_MAX)
{
throw Py::ValueError("rows and cols must both be less than 32768");
sprintf(msg, "rows and cols must both be less than %d", INT_MAX);
throw Py::ValueError(msg);
}



if (bounds.length() != 4)
{
throw Py::TypeError("Incorrect number of bounds (4 expected)");
Expand Down
1 change: 1 addition & 0 deletions src/_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef _IMAGE_H
#define _IMAGE_H
#include <utility>
#include <climits>
#include "Python.h"

#include "agg_trans_affine.h"
Expand Down
3 changes: 2 additions & 1 deletion src/cntr.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@

/* the data about edges, zones, and points -- boundary or not, exists
* or not, z value 0, 1, or 2 -- is kept in a mesh sized data array */
typedef short Cdata;
// typedef short Cdata; // 16 bits display rendering
typedef int Cdata; // 32 bits display rendering

/* information to decide on correct contour direction in saddle zones
* is stored in a mesh sized array. Only those entries corresponding
Expand Down