Skip to content
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

Manipulating .cr2 file crashes Python process (signal 11) #3786

Closed
timo-piirmann opened this issue Apr 10, 2019 · 7 comments · Fixed by #4627
Closed

Manipulating .cr2 file crashes Python process (signal 11) #3786

timo-piirmann opened this issue Apr 10, 2019 · 7 comments · Fixed by #4627
Labels
Bug Any unexpected behavior, until confirmed feature. TIFF
Projects

Comments

@timo-piirmann
Copy link

timo-piirmann commented Apr 10, 2019

What did you do?

I was trying to open and save .cr2 image in another format.

What did you expect to happen?

I expected the file to be saved OR at least raise some kind of exception why it couldn't be done. Anything I could work with

What actually happened?

Python process crashed with the following message:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

What are your OS, Python and Pillow versions?

  • OS: macOS Mojave
  • Python: 3.6.6
  • Pillow: 6.0.0
from PIL import Image

img = Image.open("file_1.cr2")
del img.tag_v2[700]

img.save("new_file.tif")

In Pillow 5.4.1 this file wasn't identified by Pillow as image and so the code just skipped this part. But in 6.0.0 Pillow does identify it as image but after that things blow up.

image.CR2.zip

@radarhere radarhere changed the title Manipulating .cr2 file crashes python process (signal 11) Manipulating .cr2 file crashes Python process (signal 11) Apr 10, 2019
@radarhere
Copy link
Member

Testing, this became readable with #3489

On my machine, when saving I get -

OJPEGSetupEncode: OJPEG encoding not supported; use new-style JPEG compression instead.
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    im.save("new_file.tif")
  File "PIL/Image.py", line 2007, in save
  File "PIL/TiffImagePlugin.py", line 1564, in _save
OSError: encoder error -2 when writing image file

@timo-piirmann
Copy link
Author

timo-piirmann commented Apr 11, 2019

I've tried to dig a little bit deeper and my code never even reaches TiffImagePlugin._save(). The most I could debug at the moment was that it crashes during Image.save() in here:

self._ensure_mutable()

It never comes out of self._ensure_mutable()

@radarhere
Copy link
Member

If you're looking for an immediate workaround, I can offer you this -

from PIL import Image
im = Image.open('image.CR2')
im = im.transform(im.size, Image.AFFINE, [1.0, 0.0, 0.0, 0.0, 1.0, 0.0])
im.save('out.tif')

@timo-piirmann
Copy link
Author

It seems that the process crash is specific to macOS because when running this same code and image on Debian system, everything seems to work the same way that @radarhere has described.

Can't be sure but this might be related to this github issue: #3677

@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label May 11, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@radarhere radarhere added the TIFF label Aug 25, 2019
@radarhere
Copy link
Member

My current theory is this is related to #4034.

@radarhere
Copy link
Member

Testing before #4034, I was consistently getting a segfault. Now, I am consistently getting an OSError.

@radarhere
Copy link
Member

For the current form of this issue at least, the problem is that the image compression is 'tiff_jpeg'. Pillow states this is obsolete. It corresponds to OJPEG, matching the error that is seen when the code for this issue is run -

OJPEGSetupEncode: OJPEG encoding not supported; use new-style JPEG compression instead.

That error message comes from libtiff. So I've created PR #4627 to take the suggestion. As a workaround in the meantime, you could fix this specific situation by changing the compression manually.

from PIL import Image

img = Image.open("file_1.cr2")
del img.tag_v2[700]
if img.info["compression"] == "tiff_jpeg":
    img.info["compression"] = "jpeg"

img.save("new_file.tif")

Pillow automation moved this from In progress to Closed Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. TIFF
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

3 participants