diff --git a/Tests/check_large_memory.py b/Tests/check_large_memory.py index 24d687ea692..a2fcc206e28 100644 --- a/Tests/check_large_memory.py +++ b/Tests/check_large_memory.py @@ -12,6 +12,12 @@ # 2.7 and 3.2. from PIL import Image + +try: + import numpy +except ImportError: + numpy = None + YDIM = 32769 XDIM = 48000 @@ -32,6 +38,11 @@ def test_2gpx(self): """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() diff --git a/src/decode.c b/src/decode.c index 562bc743699..10e740aaf4e 100644 --- a/src/decode.c +++ b/src/decode.c @@ -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; diff --git a/src/libImaging/BcnDecode.c b/src/libImaging/BcnDecode.c index 1472b02961c..c2c4f21e7c3 100644 --- a/src/libImaging/BcnDecode.c +++ b/src/libImaging/BcnDecode.c @@ -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; diff --git a/src/libImaging/BitDecode.c b/src/libImaging/BitDecode.c index a78183542d2..7120b332138 100644 --- a/src/libImaging/BitDecode.c +++ b/src/libImaging/BitDecode.c @@ -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; diff --git a/src/libImaging/FliDecode.c b/src/libImaging/FliDecode.c index 6d22c6c4ea8..e21259900e5 100644 --- a/src/libImaging/FliDecode.c +++ b/src/libImaging/FliDecode.c @@ -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; diff --git a/src/libImaging/GifDecode.c b/src/libImaging/GifDecode.c index 58cf544009b..68429ab26c0 100644 --- a/src/libImaging/GifDecode.c +++ b/src/libImaging/GifDecode.c @@ -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; diff --git a/src/libImaging/HexDecode.c b/src/libImaging/HexDecode.c index 14f5241dc5e..8bd9bf67fa7 100644 --- a/src/libImaging/HexDecode.c +++ b/src/libImaging/HexDecode.c @@ -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; diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index e705e0a604d..25c15e758cf 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -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); diff --git a/src/libImaging/Jpeg2KDecode.c b/src/libImaging/Jpeg2KDecode.c index 9140e007415..f2e437dda28 100644 --- a/src/libImaging/Jpeg2KDecode.c +++ b/src/libImaging/Jpeg2KDecode.c @@ -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){ diff --git a/src/libImaging/JpegDecode.c b/src/libImaging/JpegDecode.c index 33cc5d0955b..39d96de531b 100644 --- a/src/libImaging/JpegDecode.c +++ b/src/libImaging/JpegDecode.c @@ -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; diff --git a/src/libImaging/PackDecode.c b/src/libImaging/PackDecode.c index aea8f04e301..ef54f3c9a4f 100644 --- a/src/libImaging/PackDecode.c +++ b/src/libImaging/PackDecode.c @@ -18,7 +18,7 @@ int ImagingPackbitsDecode(Imaging im, ImagingCodecState state, - UINT8* buf, int bytes) + UINT8* buf, Py_ssize_t bytes) { UINT8 n; UINT8* ptr; diff --git a/src/libImaging/PcdDecode.c b/src/libImaging/PcdDecode.c index f9234389023..8ff264edfc8 100644 --- a/src/libImaging/PcdDecode.c +++ b/src/libImaging/PcdDecode.c @@ -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; diff --git a/src/libImaging/PcxDecode.c b/src/libImaging/PcxDecode.c index e5417f1bdd0..4a5931bee73 100644 --- a/src/libImaging/PcxDecode.c +++ b/src/libImaging/PcxDecode.c @@ -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; diff --git a/src/libImaging/RawDecode.c b/src/libImaging/RawDecode.c index 40c0cb79a41..774d4245b85 100644 --- a/src/libImaging/RawDecode.c +++ b/src/libImaging/RawDecode.c @@ -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; diff --git a/src/libImaging/SgiRleDecode.c b/src/libImaging/SgiRleDecode.c index 9d8e56376ce..f87c473e3cd 100644 --- a/src/libImaging/SgiRleDecode.c +++ b/src/libImaging/SgiRleDecode.c @@ -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; diff --git a/src/libImaging/SunRleDecode.c b/src/libImaging/SunRleDecode.c index 50d816e387f..e627c2c9a28 100644 --- a/src/libImaging/SunRleDecode.c +++ b/src/libImaging/SunRleDecode.c @@ -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; diff --git a/src/libImaging/TgaRleDecode.c b/src/libImaging/TgaRleDecode.c index cad6bc3bcfe..d1971e54623 100644 --- a/src/libImaging/TgaRleDecode.c +++ b/src/libImaging/TgaRleDecode.c @@ -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; diff --git a/src/libImaging/TiffDecode.c b/src/libImaging/TiffDecode.c index 381f795e01d..a68f73993ff 100644 --- a/src/libImaging/TiffDecode.c +++ b/src/libImaging/TiffDecode.c @@ -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"; diff --git a/src/libImaging/XbmDecode.c b/src/libImaging/XbmDecode.c index 8a203841bef..75b4961abaa 100644 --- a/src/libImaging/XbmDecode.c +++ b/src/libImaging/XbmDecode.c @@ -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 }; diff --git a/src/libImaging/ZipDecode.c b/src/libImaging/ZipDecode.c index e96e3200c14..43601c38eeb 100644 --- a/src/libImaging/ZipDecode.c +++ b/src/libImaging/ZipDecode.c @@ -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;