-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
PNG max dimensions #436
Comments
Yeah, well, that's big. The OOM killer gets me when numpy is allocating the second bunch of memory. (at least, on my dev vm. I can try this on something bigger) I think that the fromarray is a memory copy, I'm pretty sure that the direct Image.new is an equivalent call without the dependencies. A more concise test would be something like:
|
Actually, I think this is more fundamental:
It looks like there's an issue somewhere with images that are greater than 2 GB. |
Cool, thanks for taking a look. Maybe there is hope someone is using an signed int32 in a x64 build? |
Does look that way, doesn't it. I think this is it: https://github.com/python-imaging/Pillow/blob/master/_imaging.c#L3076 |
So, FWIW: In this case, it's because of a function returning a Py_ssize_t (a signed 64 bit integer) by calling return xsize * ysize, which were both signed 32bit ints. If that was > 2gpix, then it overflowed into negative values. That was then cast to a Py_ssize_t as a simple widening, preserving the sign. Casting before returning prevents the overflow. Try that patch and see what it does for you. |
Thanks for chasing that down. I haven’t debugged Python extensions before. Out of curiosity with that fix is there any limit to PNG dimensions? Anything I can do to help? |
Test it. I checked the basics this morning and it was able to save a 64k-1x64k-1 png. It took 4 gigs of memory to do it, but it worked. As I noted in the pull request, the quantization routines are limited to int32 pixels, and it's a little more complicated to fix than just a few casts. (and, I'd have to touch up the testing, and to do that, understand what the quantization is really doing). |
I’m trying to test the fix, but I am having trouble with building. Setup.py build claims I have ZLIB support. Selftest.py claims the support is missing. The log is below. Any ideas? Thanks. c:\Src\Git\Pillow>python setup.py build running build_extPIL SETUP SUMMARYversion Pillow 2.3.0 [MSC v.1500 64 bit (AMD64)]*** TKINTER support not available *** WEBPMUX support not availableTo add a missing option, make sure you have the required To check the build, run the selftest.py script. running build_scripts c:\Src\Git\Pillow>python selftest.pyPillow 2.3.0 TEST SUMMARYPython modules loaded from c:\Src\Git\Pillow\PIL Binary modules loaded from c:\Src\Git\Pillow\PIL--- PIL CORE support ok *** WEBP support not installedRunning selftest: File "c:\Src\Git\Pillow\selftest.py", line 57, in selftest.testimage 1 items had failures: |
Nevermind. I think what is happening is I have a failure at link time, but the setup package found zlib and jpeg files so the summary is claiming they are there. |
I’ve got a build with the fix running. Using my original test I no longer get the same error However there is an access violation occurring sometime after the file is created and some data is written to it. I’m building a debug version of pillow so I can provide more detailed information than an address but I need to find/build python_d first. I did not use the simplified “Allocate an image and save it”. I am using the fromarray using a numpy array. It is entirely possible I have strangeness in my build somewhere. I don’t have JPG support to run the selftest.py yet. I’ll let you know once I have a cleaner story. It may be Monday before I can get back to working on code. Thanks |
I built a debug version of python windows once, and... It did work, but it wasn't a pleasant experience. These days, I'm using Ubuntu, where I can just install the package. (Though, I read something on integrated python/C debugging in the latest visual studio, which would be nice.) |
Yea… I gave up for the night. I can actually build Python_d in Windows with the included solution. I got Pillow built with self.debug=True. setup tools has PDB’s turned off for visual studio for some reason so I got those generated. However when I do a debug pillow build and install it I cannot from PIL import Image. If I run python from the pillow directory I can import Image correctly but I think that is just an illusion. When I put the process in visual studio and crash the images don’t match so I cannot load the pdb file. I think it may be because _image is now _image_d? Anyway, if any of that seems familiar let me know. Otherwise perhaps I should try and install the debug build on a Mac I have. That is a whole different learning curve for me though. |
Sorry for the delay in getting back to you. I was taking an involuntary vacation due to weather. I’ve repeated the test of saving large PNG’s using your fix on my Mac. The stack for the next crash is below. My dev experience on the mac is limited. I can try for a debug build if it would be helpful and you are interested in chasing this further. There are some warnings thrown by the MSVC compiler regarding 64-bit portability. Process: Python [25893] Date/Time: 2013-12-12 21:39:32.082 -0800 Sleep/Wake UUID: 1EB2C86F-581A-4A95-BF3A-D4723BCB6EF4 Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) VM Regions Near 0xe9905e00: Thread 0 Crashed:: Dispatch queue: com.apple.main-thread Thread 0 crashed with X86 Thread State (64-bit): Logical CPU: 2 Binary Images: External Modification Summary: VM Region Summary: REGION TYPE VIRTUAL Model: MacBookAir6,2, BootROM MBA61.0099.B04, 2 processors, Intel Core i7, 1.7 GHz, 8 GB, SMC 2.13f7 |
What's the python code that triggers this? |
This file: On Dec 12, 2013, at 10:27 PM, wiredfool <notifications@github.commailto:notifications@github.com> wrote: What's the python code that triggers this? — |
Ok, so I get an error on ubuntu as well in the same spot:
Ok, that last one is a smoking gun. Pretty sure that the error is in storage.c, where all the pointers to the rows are setup. Or not. I'll pick it up in the morning. |
s/morning/evening/; It was in map.c, not storage.c. Give this a whirl and see what you get. |
Looks like the fixed worked. Thanks! The test ran successfully. The 48,000 x 48,000 pixel image was able to open with Mac Preview app. |
Pillow is raising an exception when attempting to write large PNG's with dimensions larger than a signed 16-bit integer. Previously I believed that the maximum dimension was 65536x65536 but the spec states the dimension is stored in 4 bytes. http://www.libpng.org/pub/png/spec/iso/index-object.html#11IHDR I am requesting support for 65K.
Oddly Pillow is able to write images with both dimensions larger than 2 << 31. Where the limit for crashing lives isn't clear to me yet.
This is running on Win7 x64 using Pillow 2.2.1 and Python 2.7.6 x64. Pillow was downloaded from Gohlke's site. Scipy is 13.1 and numpy is 1.8
I've done some debugging and the crash appears to occur in Image.load. Referencing the Images "im" member results in a "SystemError: error return without exception set" This is where I got stuck.
I've uploaded code that reproduces the behavior to https://github.com/jamesra/random/blob/master/pillow_png_size.py
I try to avoid PNG's of this size but I have ported some code from ITK (C++) to Scipy/Pillow and the lower limit creates a backward compatibility issue for me.
If this is fixable within the python code with a couple hours of time I'm willing to attempt it. Eclipse wasn't letting me dig past the self.im line that throws the exception.
The text was updated successfully, but these errors were encountered: