Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75595da

Browse files
Change hard coded limits of (32768, 32768) pixels for an image to a platform dependant size of (INT_MAX, INT_MAX)
1 parent c9eb4df commit 75595da

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/_backend_agg.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,9 +2518,11 @@ Py::Object _backend_agg_module::new_renderer(const Py::Tuple &args,
25182518
unsigned int height = (int)Py::Int(args[1]);
25192519
double dpi = Py::Float(args[2]);
25202520

2521-
if (width > 1 << 15 || height > 1 << 15)
2521+
char msg [256];
2522+
if (width > INT_MAX || height > INT_MAX)
25222523
{
2523-
throw Py::ValueError("width and height must each be below 32768");
2524+
sprintf(msg, "width and height must each be below %d", INT_MAX);
2525+
throw Py::ValueError(msg);
25242526
}
25252527

25262528
if (dpi <= 0.0)

src/_backend_agg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef __BACKEND_AGG_H
88
#define __BACKEND_AGG_H
99
#include <utility>
10+
#include <climits>
1011
#include "CXX/Extensions.hxx"
1112

1213
#include "agg_arrowhead.h"

src/_image.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,11 @@ _image_module::from_images(const Py::Tuple& args)
786786
size_t numrows = (long)Py::Int(args[0]);
787787
size_t numcols = (long)Py::Int(args[1]);
788788

789-
if (numrows >= 32768 || numcols >= 32768)
789+
char msg [256];
790+
if (numrows >= INT_MAX || numcols >= INT_MAX)
790791
{
791-
throw Py::RuntimeError("numrows and numcols must both be less than 32768");
792+
sprintf(msg, "numrows and numcols must both be less than %d", INT_MAX);
793+
throw Py::ValueError(msg);
792794
}
793795

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

1271-
if (x >= 32768 || y >= 32768)
1273+
char msg [256];
1274+
if (x >= INT_MAX || y >= INT_MAX)
12721275
{
1273-
throw Py::ValueError("x and y must both be less than 32768");
1276+
sprintf(msg, "numrows and numcols must both be less than %d", INT_MAX);
1277+
throw Py::ValueError(msg);
12741278
}
12751279

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

1579-
if (rows >= 32768 || cols >= 32768)
1583+
char msg [256];
1584+
if (rows >= INT_MAX || cols >= INT_MAX)
15801585
{
1581-
throw Py::ValueError("rows and cols must both be less than 32768");
1586+
sprintf(msg, "rows and cols must both be less than %d", INT_MAX);
1587+
throw Py::ValueError(msg);
15821588
}
15831589

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

1825-
if (rows >= 32768 || cols >= 32768)
1831+
char msg [256];
1832+
if (rows >= INT_MAX || cols >= INT_MAX)
18261833
{
1827-
throw Py::ValueError("rows and cols must both be less than 32768");
1834+
sprintf(msg, "rows and cols must both be less than %d", INT_MAX);
1835+
throw Py::ValueError(msg);
18281836
}
18291837

1838+
1839+
18301840
if (bounds.length() != 4)
18311841
{
18321842
throw Py::TypeError("Incorrect number of bounds (4 expected)");

src/_image.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef _IMAGE_H
88
#define _IMAGE_H
99
#include <utility>
10+
#include <climits>
1011
#include "Python.h"
1112

1213
#include "agg_trans_affine.h"

0 commit comments

Comments
 (0)