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
OverflowError in PIL.Image.fromarray #1475
Comments
There are some tests for large images |
@birgander2 What's the full trace? |
And I have to correct myself, the array has only shape (36352, 18144) |
From my tests, here is the minimal code required to produce the problem - import numpy
from PIL import Image
array = numpy.ndarray(shape=(16384, 16384))
Image.fromarray(array) So the limit is not 2 ** 31, it's 2 ** 28. |
Can you try running the large memory test listed above? |
Both of the large memory tests pass for me. |
@birgander2 What platform are you on, and are you on a 64 bit python? |
I'm on linux using python 3.4.3 with pillow 3.0.0. And yes, it is 64bit python. |
These tests pass slowly: def _write_png(self, xdim, ydim):
dtype = np.uint8
a = np.zeros((xdim, ydim), dtype=dtype)
f = self.tempfile('temp.png')
im = Image.fromarray(a, 'L')
im.save(f)
def test_large(self):
""" succeeded prepatch"""
self._write_png(XDIM, YDIM)
def test_2gpx(self):
"""failed prepatch"""
self._write_png(XDIM, XDIM)
def test_1475(self):
""" issue #1475 """
self._write_png(36352, 18144) This test fails: a = np.zeros((36352, 18144), dtype=np.float)
im = Image.fromarray(a, mode='F') I'm digging in to see where we're actually failing, but it does appear that the float has something to do with it. |
Yep. There's an int length in there. What's happening is that for some cases, we need to decode the bytes. That's effectively here in decode.c: UINT8* buffer;
int bufsize, status;
ImagingSectionCookie cookie;
if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH, &buffer, &bufsize))
return NULL; It's an integer bufsize. It looks like it can be fixed by changing all the ints to py_ssize_t, and defining |
PIL.Image.frombuffer() raises OverflowError on buffers >= 2 GB when mapping color channels (python-pillow/Pillow#1475). Work around this by loading large buffers in smaller chunks and pasting them into the result image. Fixes #17.
Hi, is there some progress in this issue? |
No progress. |
Thanks for the info @wiredfool . I suppose it's not something with high priority. Will resort to a workaround instead. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@wiredfool's suggestion was coincidentally implemented in #3749. With that PR, the error here changes from 'OverflowError: size does not fit in an int' to 'ValueError: not enough image data'. I have created PR #3791 to take the last step to resolve this. |
When trying o generate a huge image (73067 x 28160) from a numpy ndarray, pillow throws me an
"OverflowError: size does not fit in an int". Is pillow limited to maximum sizes of below 2**31bit?
I used:
The text was updated successfully, but these errors were encountered: