Changed decode buffer size to Py_ssize_t

This commit is contained in:
Andrew Murray 2019-04-15 17:33:28 +10:00
parent 9c4ed695e4
commit ca1cf59251
20 changed files with 48 additions and 37 deletions

View File

@ -12,6 +12,12 @@ from .helper import unittest, PillowTestCase
# 2.7 and 3.2.
from PIL import Image
try:
import numpy
except ImportError:
numpy = None
YDIM = 32769
XDIM = 48000
@ -32,6 +38,11 @@ class LargeMemoryTest(PillowTestCase):
"""failed prepatch"""
self._write_png(XDIM, XDIM)
@unittest.skipIf(numpy is None, "Numpy is not installed")
def test_size_greater_than_int(self):
arr = numpy.ndarray(shape=(16394, 16394))
Image.fromarray(arr)
if __name__ == '__main__':
unittest.main()

View File

@ -48,7 +48,7 @@
typedef struct {
PyObject_HEAD
int (*decode)(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
int (*cleanup)(ImagingCodecState state);
struct ImagingCodecStateInstance state;
Imaging im;

View File

@ -844,7 +844,7 @@ static int decode_bcn(Imaging im, ImagingCodecState state, const UINT8* src, int
return (int)(ptr - src);
}
int ImagingBcnDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) {
int ImagingBcnDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) {
int N = state->state & 0xf;
int width = state->xsize;
int height = state->ysize;

View File

@ -20,7 +20,7 @@
int
ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
BITSTATE* bitstate = state->context;
UINT8* ptr;

View File

@ -26,7 +26,7 @@
int
ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
UINT8* ptr;
int framesize;

View File

@ -58,7 +58,7 @@
int
ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes)
ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ssize_t bytes)
{
UINT8* p;
UINT8* out;

View File

@ -21,7 +21,7 @@
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : -1)
int
ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
UINT8* ptr;
int a, b;

View File

@ -413,22 +413,22 @@ typedef int (*ImagingCodec)(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingBcnDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingBitDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingEpsEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingFliDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingGifDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingGifEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingHexDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
#ifdef HAVE_LIBJPEG
extern int ImagingJpegDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingJpegDecodeCleanup(ImagingCodecState state);
extern int ImagingJpegUseJCSExtensions(void);
@ -437,7 +437,7 @@ extern int ImagingJpegEncode(Imaging im, ImagingCodecState state,
#endif
#ifdef HAVE_OPENJPEG
extern int ImagingJpeg2KDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingJpeg2KDecodeCleanup(ImagingCodecState state);
extern int ImagingJpeg2KEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
@ -445,44 +445,44 @@ extern int ImagingJpeg2KEncodeCleanup(ImagingCodecState state);
#endif
#ifdef HAVE_LIBTIFF
extern int ImagingLibTiffDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingLibTiffEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
#endif
#ifdef HAVE_LIBMPEG
extern int ImagingMpegDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
#endif
extern int ImagingMspDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingPcdDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingPcxDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingPcxEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingRawDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingRawEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingSgiRleDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingSgiRleDecodeCleanup(ImagingCodecState state);
extern int ImagingSunRleDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingTgaRleEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingXbmDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingXbmEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
#ifdef HAVE_LIBZ
extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, Py_ssize_t bytes);
extern int ImagingZipDecodeCleanup(ImagingCodecState state);
extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);

View File

@ -769,7 +769,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state)
}
int
ImagingJpeg2KDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingJpeg2KDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
if (bytes){

View File

@ -144,7 +144,7 @@ output(j_common_ptr cinfo)
/* -------------------------------------------------------------------- */
int
ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
JPEGSTATE* context = (JPEGSTATE*) state->context;
int ok;

View File

@ -18,7 +18,7 @@
int
ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
UINT8* buf, int bytes)
UINT8* buf, Py_ssize_t bytes)
{
UINT8 n;
UINT8* ptr;

View File

@ -24,7 +24,7 @@
int
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
int x;
int chunk;

View File

@ -17,7 +17,7 @@
#include "Imaging.h"
int
ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
UINT8 n;
UINT8* ptr;

View File

@ -20,7 +20,7 @@
int
ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
enum { LINE = 1, SKIP };
RAWSTATE* rawstate = state->context;

View File

@ -90,7 +90,7 @@ static int expandrow2(UINT16* dest, UINT16* src, int n, int z)
int
ImagingSgiRleDecode(Imaging im, ImagingCodecState state,
UINT8* buf, int bytes)
UINT8* buf, Py_ssize_t bytes)
{
UINT8 *ptr;
SGISTATE *c;

View File

@ -20,7 +20,7 @@
int
ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
int n;
UINT8* ptr;

View File

@ -20,7 +20,7 @@
int
ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
UINT8* buf, int bytes)
UINT8* buf, Py_ssize_t bytes)
{
int n, depth;
UINT8* ptr;

View File

@ -275,7 +275,7 @@ int ReadStrip(TIFF* tiff, UINT32 row, UINT32* buffer) {
return 0;
}
int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) {
int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ssize_t bytes) {
TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
char *filename = "tempfile.tif";
char *mode = "r";

View File

@ -21,7 +21,7 @@
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : 0)
int
ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
enum { BYTE = 1, SKIP };

View File

@ -41,7 +41,7 @@ static int get_row_len(ImagingCodecState state, int pass)
/* -------------------------------------------------------------------- */
int
ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
ZIPSTATE* context = (ZIPSTATE*) state->context;
int err;