Skip to content

Segmentation fault #1597

Closed
Closed

Description

@playnet

rdf.zip
github don't eat .tif file, unzip it and

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL.Image
>>> filename="rdf.tif"
>>> img = PIL.Image.open(filename)
>>> img.info
{'resolution': (72.0, 72.0), 'compression': 'tiff_lzw'}
>>> img.size
(518, 556)
>>> img.save("rdf.1.tif", format='TIFF')
Segmentation fault

$ pip show Pillow

---
Name: Pillow
Version: 3.0.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: 

$ dpkg -l|grep tiff
ii  libtiff-tools                               4.0.3-7ubuntu0.3                                    amd64        TIFF manipulation and conversion tools
ii  libtiff4:amd64                              3.9.7-2ubuntu1                                      amd64        Tag Image File Format (TIFF) library (old version)
ii  libtiff5:amd64                              4.0.3-7ubuntu0.3                                    amd64        Tag Image File Format (TIFF) library
ii  libtiff5:i386                               4.0.3-7ubuntu0.3                                    i386         Tag Image File Format (TIFF) library
ii  libtiff5-dev:amd64                          4.0.3-7ubuntu0.3                                    amd64        Tag Image File Format library (TIFF), development files
ii  libtiffxx5:amd64                            4.0.3-7ubuntu0.3                                    amd64        Tag Image File Format (TIFF) library -- C++ interface

uname -a
Linux playnet 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=17.2
DISTRIB_CODENAME=rafaela
DISTRIB_DESCRIPTION="Linux Mint 17.2 Rafaela"

And

Linux build64 2.6.32-042stab111.12 #1 SMP Thu Sep 17 11:38:20 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux
$cat /etc/redhat-release 
CentOS release 6.7 (Final)
$python -V
Python 2.6.6

Activity

  1. hugovk commented on Dec 15, 2015

    @hugovk
    Member

    On Windows 7/Python 2.7 I don't see a segmentation fault but get a "Python has stopped working" UI popup and a crash, so probably the same thing.

    Pillow 2.9.0 isn't quite as bad:

    >>> img.save("rdf.1.tif", format='TIFF')
    _TIFFVSetField: rdf.1.tif: Bad value 2 for "ExtraSamples" tag.
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python27\lib\site-packages\PIL\Image.py", line 1703, in save
        save_handler(self, fp, filename)
      File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 1236, in _save
        e = Image._getencoder(im.mode, 'libtiff', a, im.encoderconfig)
      File "C:\Python27\lib\site-packages\PIL\Image.py", line 435, in _getencoder
        return encoder(mode, *args + extra)
    RuntimeError: Error setting from dictionary
    >>>
    
  2. wiredfool commented on Dec 15, 2015

    @wiredfool
    Member

    It's dying in the metadata, (tag 318: WhitePoint) which is It's the big exif reorg, which is now passing more items into the list of metadata that's being saved by libtiff.

    test.py:

    #!/usr/bin/env python
    from PIL import Image
    im = Image.open('rdf.tif')
    im.save('out.tif', format='TIFF')
    
    (vpy27-dbg)erics@builder-1204-x64:~/issue_1597$ gdb python
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://bugs.launchpad.net/gdb-linaro/>...
    Reading symbols from /home/erics/vpy27-dbg/bin/python...done.
    (gdb) r test.py
    Starting program: /home/erics/vpy27-dbg/bin/python test.py
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    
    Program received signal SIGSEGV, Segmentation fault.
    __memcpy_ssse3 () at ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:1816
    1816    ../sysdeps/x86_64/multiarch/memcpy-ssse3.S: No such file or directory.
    (gdb) bt
    #0  __memcpy_ssse3 () at ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:1816
    #1  0x00007ffff5b7964b in ?? () from /usr/lib/x86_64-linux-gnu/libtiff.so.4
    #2  0x00007ffff606c800 in ImagingLibTiffSetField (state=0xefd268, tag=318) at libImaging/TiffDecode.c:341
    #3  0x00007ffff603b6db in PyImaging_LibTiffEncoderNew (self=0x0, args=0xb86060) at encode.c:785
    #4  0x0000000000486896 in PyCFunction_Call (func=0xc97df8, arg=0xb86060, kw=0x0) at ../Objects/methodobject.c:81
    #5  0x00000000005278e4 in ext_do_call (func=0xc97df8, pp_stack=0x7fffffffd040, flags=1, na=1, nk=0) at ../Python/ceval.c:4331
    #6  0x00000000005215cd in PyEval_EvalFrameEx (f=0xf46c90, throwflag=0) at ../Python/ceval.c:2705
    #7  0x0000000000523c2e in PyEval_EvalCodeEx (co=0xb245c0, globals=0xb50700, locals=0x0, args=0xf464c8, argcount=4, kws=0xf464e8, 
        kwcount=0, defs=0xd23da8, defcount=1, closure=0x0) at ../Python/ceval.c:3253
    #8  0x0000000000526a42 in fast_function (func=0xd26840, pp_stack=0x7fffffffd500, n=4, na=4, nk=0) at ../Python/ceval.c:4117
    #9  0x0000000000526631 in call_function (pp_stack=0x7fffffffd500, oparg=4) at ../Python/ceval.c:4042
    #10 0x0000000000521326 in PyEval_EvalFrameEx (f=0xf46240, throwflag=0) at ../Python/ceval.c:2666
    #11 0x0000000000523c2e in PyEval_EvalCodeEx (co=0xda4930, globals=0xd7f0d0, locals=0x0, args=0xf41390, argcount=3, kws=0xf413a8, 
        kwcount=0, defs=0x0, defcount=0, closure=0x0) at ../Python/ceval.c:3253
    #12 0x0000000000526a42 in fast_function (func=0xed0c30, pp_stack=0x7fffffffd9c0, n=3, na=3, nk=0) at ../Python/ceval.c:4117
    #13 0x0000000000526631 in call_function (pp_stack=0x7fffffffd9c0, oparg=3) at ../Python/ceval.c:4042
    #14 0x0000000000521326 in PyEval_EvalFrameEx (f=0xf411b0, throwflag=0) at ../Python/ceval.c:2666
    #15 0x0000000000523c2e in PyEval_EvalCodeEx (co=0xb825c0, globals=0xb50700, locals=0x0, args=0xb562c8, argcount=2, kws=0xb562d8, 
        kwcount=1, defs=0xd28408, defcount=1, closure=0x0) at ../Python/ceval.c:3253
    #16 0x0000000000526a42 in fast_function (func=0xd29d80, pp_stack=0x7fffffffde80, n=4, na=2, nk=1) at ../Python/ceval.c:4117
    #17 0x0000000000526631 in call_function (pp_stack=0x7fffffffde80, oparg=257) at ../Python/ceval.c:4042
    #18 0x0000000000521326 in PyEval_EvalFrameEx (f=0xb56140, throwflag=0) at ../Python/ceval.c:2666
    #19 0x0000000000523c2e in PyEval_EvalCodeEx (co=0x9c80f0, globals=0x9f2710, locals=0x9f2710, args=0x0, argcount=0, kws=0x0, 
        kwcount=0, defs=0x0, defcount=0, closure=0x0) at ../Python/ceval.c:3253
    #20 0x0000000000519dd2 in PyEval_EvalCode (co=0x9c80f0, globals=0x9f2710, locals=0x9f2710) at ../Python/ceval.c:667
    #21 0x00000000005567f0 in run_mod (mod=0xb61d08, filename=0x7fffffffe81b "test.py", globals=0x9f2710, locals=0x9f2710, 
        flags=0x7fffffffe480, arena=0xa57f50) at ../Python/pythonrun.c:1353
    #22 0x0000000000556776 in PyRun_FileExFlags (fp=0x9f2980, filename=0x7fffffffe81b "test.py", start=257, globals=0x9f2710, 
        locals=0x9f2710, closeit=1, flags=0x7fffffffe480) at ../Python/pythonrun.c:1339
    #23 0x0000000000555010 in PyRun_SimpleFileExFlags (fp=0x9f2980, filename=0x7fffffffe81b "test.py", closeit=1, flags=0x7fffffffe480)
        at ../Python/pythonrun.c:943
    #24 0x0000000000554654 in PyRun_AnyFileExFlags (fp=0x9f2980, filename=0x7fffffffe81b "test.py", closeit=1, flags=0x7fffffffe480)
        at ../Python/pythonrun.c:747
    #25 0x000000000056fc6a in Py_Main (argc=2, argv=0x7fffffffe5c8) at ../Modules/main.c:639
    #26 0x0000000000418f14 in main (argc=2, argv=0x7fffffffe5c8) at ../Modules/python.c:23
    
  3. playnet commented on Dec 15, 2015

    @playnet
    Author

    But "convert" from ImageMagick works absolutely right

  4. playnet commented on Dec 15, 2015

    @playnet
    Author

    $ convert -density 204x98 -units PixelsPerInch -resize 1728x1186! -monochrome -compress Fax rdf.tif rdf.resampled.tif
    $ ls -la rdf.resampled.tif
    -rw-r--r-- 1 playnet playnet 37275 дек. 15 19:46 rdf.resampled.tif

  5. wiredfool commented on Dec 15, 2015

    @wiredfool
    Member

    It looks like things are sane at least to the level of

    #3  0x00007ffff603b6db in PyImaging_LibTiffEncoderNew (self=0x0, args=0xb86060) at encode.c:785
    

    but then I can't verify that the varargs are correct in the next call.

  6. wiredfool commented on Dec 15, 2015

    @wiredfool
    Member

    So, it looks like this is a 'custom tag' which requires special handling for libtiff to write. Custom being that it's not hardcoded in the list of tags that it handles without specifying the tag/type/etc.

    This is going to take work in the guts of the libtiff encoding code.

  7. playnet commented on Dec 16, 2015

    @playnet
    Author

    anywhere, segfault is a bug. Possible - (silent) drop these tags...

  8. added
    Bug
    on Dec 16, 2015
  9. playnet commented on Dec 17, 2015

    @playnet
    Author

    and possible another bug - same pic, convert("1") + resize - crop and corrupt image, but can save it. Tag corrupt body in convert?

  10. wiredfool commented on Dec 17, 2015

    @wiredfool
    Member

    What's the code that causes the last problem. Does it still happen with just the convert?

  11. wiredfool commented on Dec 17, 2015

    @wiredfool
    Member

    Actually, it looks like RGBA is the only destination mode where convert works properly.

  12. wiredfool commented on Dec 17, 2015

    @wiredfool
    Member

    @playnet Try converting any PA image to RGBA before doing anything else. And possibly before saving as a tiff as well. I'm thinking that a Palette image just isn't going to work through libtiff at this point.

  13. wiredfool commented on Dec 30, 2015

    @wiredfool
    Member

    Can we distribute that image (rdf,tif) as a test image under the Pillow license?

  14. added 2 commits that reference this issue on Dec 30, 2015
  15. radarhere commented on Dec 22, 2018

    @radarhere
    Member

    Just as a summary - the segfault is resolved by #1620, correctly saving custom tag 318 is likely to be connected to #660, and converting the image is #1600.

  16. hugovk commented on Dec 22, 2018

    @hugovk
    Member

    Thanks, closing. Can re-open if not covered by those.

  17. radarhere commented on Dec 26, 2018

    @radarhere
    Member

    So my thinking was that #660 was about int custom tags, and so was resolved by #3350, while #2745 was about string custom tags. I see now that the custom tag in this issue is a tuple.

  18. radarhere commented on Oct 24, 2025

    @radarhere
    Member

    #9241 means that Pillow 12.0.0 will now save the 318 tag by default, as in the rdf.zip code from the beginning of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTIFF

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions