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. # 2.7 and 3.2.
from PIL import Image from PIL import Image
try:
import numpy
except ImportError:
numpy = None
YDIM = 32769 YDIM = 32769
XDIM = 48000 XDIM = 48000
@ -32,6 +38,11 @@ class LargeMemoryTest(PillowTestCase):
"""failed prepatch""" """failed prepatch"""
self._write_png(XDIM, XDIM) 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__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

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

View File

@ -844,7 +844,7 @@ static int decode_bcn(Imaging im, ImagingCodecState state, const UINT8* src, int
return (int)(ptr - src); 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 N = state->state & 0xf;
int width = state->xsize; int width = state->xsize;
int height = state->ysize; int height = state->ysize;

View File

@ -20,7 +20,7 @@
int 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; BITSTATE* bitstate = state->context;
UINT8* ptr; UINT8* ptr;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -144,7 +144,7 @@ output(j_common_ptr cinfo)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int 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; JPEGSTATE* context = (JPEGSTATE*) state->context;
int ok; int ok;

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@
int 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 }; enum { LINE = 1, SKIP };
RAWSTATE* rawstate = state->context; RAWSTATE* rawstate = state->context;

View File

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

View File

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

View File

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

View File

@ -275,7 +275,7 @@ int ReadStrip(TIFF* tiff, UINT32 row, UINT32* buffer) {
return 0; 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; TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
char *filename = "tempfile.tif"; char *filename = "tempfile.tif";
char *mode = "r"; char *mode = "r";

View File

@ -21,7 +21,7 @@
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : 0) (v >= 'A' && v <= 'F') ? v - 'A' + 10 : 0)
int 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 }; enum { BYTE = 1, SKIP };

View File

@ -41,7 +41,7 @@ static int get_row_len(ImagingCodecState state, int pass)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int 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; ZIPSTATE* context = (ZIPSTATE*) state->context;
int err; int err;