Repository: scikit-image/scikit-image

Issue:
Segfault caused by skimage.io.imread on MPO files
## Description
I'm running caffe on millions of images and one certain image caused segmentation fault and aborted the whole process while being read by skimage.io.

Code gist:
```python
import skimage.io
try:
  im = skimage.io.imread(fname)
  ...
except:
  ...
```
Error message:
```
*** Error in `python`: free(): invalid size: 0x000000000b5cb340 ***
```

Here is this image https://cloud.githubusercontent.com/assets/13360214/21850830/6aadccd6-d847-11e6-84d6-e6e955592957.jpg . Reading it through `cv2` works fine but `skimage.io` causes segmentation fault.

Environments:
- ubuntu 12.04
- python 2.7.11, anaconda 2.2.0
- skimage 0.12.3

The backtrace of reading this image by `skimage.io.imread`:
```
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/username/anaconda/bin/python...done.
(gdb) run -c 'import skimage.io; skimage.io.imread("segfault.jpg")'
Starting program: /home/username/anaconda/bin/python -c 'import skimage.io; skimage.io.imread("segfault.jpg")'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffedf40700 (LWP 30490)]
[New Thread 0x7fffed73f700 (LWP 30491)]
[New Thread 0x7fffeaf3e700 (LWP 30492)]

Program received signal SIGSEGV, Segmentation fault.
0x00007fffe22a2d47 in decompress_onepass (cinfo=0x1901f70, output_buf=0x18e51e8) at jdcoefct.c:188
188	jdcoefct.c: No such file or directory.
(gdb) bt
#0  0x00007fffe22a2d47 in decompress_onepass (cinfo=0x1901f70, output_buf=0x18e51e8) at jdcoefct.c:188
#1  0x00007fffe22a822e in process_data_simple_main (cinfo=0x1901f70, output_buf=0x7fffd776f4c8, out_row_ctr=0x7fffffffc3bc, out_rows_avail=1) at jdmainct.c:355
#2  0x00007fffe22a071a in jpeg_read_scanlines (cinfo=cinfo@entry=0x1901f70, scanlines=scanlines@entry=0x7fffd776f4c8, max_lines=max_lines@entry=1) at jdapistd.c:174
#3  0x00007fffe2508380 in ImagingJpegDecode (im=0x18bb530, state=0x7fffd776f490, buf=0x1923074 "", bytes=65536) at libImaging/JpegDecode.c:232
#4  0x00007fffe24e3cb5 in _decode (decoder=0x7fffd776f470, args=<optimized out>) at decode.c:130
#5  0x00007ffff7aefe15 in call_function (oparg=<optimized out>, pp_stack=0x7fffffffc588) at Python/ceval.c:4350
#6  PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2987
#7  0x00007ffff7aefb95 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7fffffffc6f8, func=0x7fffd77c3578) at Python/ceval.c:4436
#8  call_function (oparg=<optimized out>, pp_stack=0x7fffffffc6f8) at Python/ceval.c:4371
#9  PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2987
#10 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7fffe27561b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=1, kws=0x7fffd77dded8, kwcount=0, defs=0x7fffe175d328, 
    defcount=1, closure=0x0) at Python/ceval.c:3582
#11 0x00007ffff7aefa55 in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffc918, func=0x7fffe1760c80) at Python/ceval.c:4446
#12 call_function (oparg=<optimized out>, pp_stack=0x7fffffffc918) at Python/ceval.c:4371
#13 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2987
#14 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7fffe27bbeb0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=1, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
    at Python/ceval.c:3582
#15 0x00007ffff7a6c3a1 in function_call (func=0x7fffe1760b18, arg=0x7fffd77be2d0, kw=0x0) at Objects/funcobject.c:526
#16 0x00007ffff7a3cd23 in PyObject_Call (func=0x7fffe1760b18, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2546
#17 0x00007ffff7a3ffec in call_function_tail (args=0x7fffd77be2d0, callable=0x7fffe1760b18) at Objects/abstract.c:2578
#18 PyObject_CallFunction (callable=0x7fffe1760b18, format=<optimized out>) at Objects/abstract.c:2602
#19 0x00007ffff7a87c1b in _PyObject_GenericGetAttrWithDict (obj=0x7fffd788f8d0, name=0x7ffff7e9fab0, dict=0x0) at Objects/object.c:1439
#20 0x00007ffff08bfc04 in PyArray_GetAttrString_SuppressException (obj=obj@entry=0x7fffd788f8d0, name=name@entry=0x7ffff09d0c08 "__array_interface__") at numpy/core/src/multiarray/common.c:76
#21 0x00007ffff08cb0db in PyArray_FromInterface (origin=origin@entry=0x7fffd788f8d0) at numpy/core/src/multiarray/ctors.c:2170
#22 0x00007ffff08cda01 in PyArray_GetArrayParamsFromObject (context=<optimized out>, out_arr=0x7fffffffcf70, out_dims=0x7fffffffcf90, out_ndim=0x7fffffffcf40, out_dtype=0x7fffffffcf80, 
    writeable=0 '\000', requested_dtype=0x0, op=<optimized out>) at numpy/core/src/multiarray/ctors.c:1495
#23 PyArray_FromAny (op=op@entry=0x7fffd788f8d0, newtype=newtype@entry=0x0, min_depth=0, max_depth=0, flags=flags@entry=112, context=0x0) at numpy/core/src/multiarray/ctors.c:1687
#24 0x00007ffff08cddb5 in PyArray_CheckFromAny (op=0x7fffd788f8d0, descr=0x0, min_depth=min_depth@entry=0, max_depth=max_depth@entry=0, requires=112, context=context@entry=0x0)
    at numpy/core/src/multiarray/ctors.c:1865
#25 0x00007ffff095d76d in _array_fromobject (__NPY_UNUSED_TAGGEDignored=<optimized out>, args=<optimized out>, kws=0x7fffd7841168) at numpy/core/src/multiarray/multiarraymodule.c:1714
#26 0x00007ffff7aef747 in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7fffffffd2e8, func=0x7ffff7e3e5a8) at Python/ceval.c:4565
#27 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd2e8) at Python/ceval.c:4373
#28 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2987
#29 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7fffdbac1bb0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=1, kws=0xbed980, kwcount=2, defs=0x7fffdbaac458, 
    defcount=2, closure=0x0) at Python/ceval.c:3582
#30 0x00007ffff7aefa55 in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffd508, func=0x7fffdb660a28) at Python/ceval.c:4446
#31 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd508) at Python/ceval.c:4371
#32 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2987
#33 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7fffdbabcc30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=1, kws=0x7ffff7f97068, kwcount=0, defs=0x7fffdbaac4a0, 
    defcount=2, closure=0x0) at Python/ceval.c:3582
#34 0x00007ffff7a6c4a8 in function_call (func=0x7fffdb6609b0, arg=0x7fffe178f050, kw=0x7fffd783aa28) at Objects/funcobject.c:526
#35 0x00007ffff7a3cd23 in PyObject_Call (func=0x7fffdb6609b0, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2546
#36 0x00007ffff7aed797 in ext_do_call (nk=-512167856, na=<optimized out>, flags=<optimized out>, pp_stack=0x7fffffffd7f8, func=0x7fffdb6609b0) at Python/ceval.c:4663
#37 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3026
#38 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7fffe2796830, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=2, kws=0x7fffd785be78, kwcount=1, defs=0x0, defcount=0, 
    closure=0x0) at Python/ceval.c:3582
#39 0x00007ffff7a6c4a8 in function_call (func=0x7fffe12b7ed8, arg=0x7fffdbaac4d0, kw=0x7fffd77d6d70) at Objects/funcobject.c:526
#40 0x00007ffff7a3cd23 in PyObject_Call (func=0x7fffe12b7ed8, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2546
#41 0x00007ffff7aed797 in ext_do_call (nk=-609565488, na=<optimized out>, flags=<optimized out>, pp_stack=0x7fffffffdae8, func=0x7fffe12b7ed8) at Python/ceval.c:4663
#42 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3026
#43 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7fffe27adab0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=1, kws=0x7ffff7fc0da8, kwcount=0, defs=0x7fffdbad6c98, 
    defcount=3, closure=0x0) at Python/ceval.c:3582
#44 0x00007ffff7aefa55 in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffdd08, func=0x7fffdb6616e0) at Python/ceval.c:4446
#45 call_function (oparg=<optimized out>, pp_stack=0x7fffffffdd08) at Python/ceval.c:4371
#46 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2987
#47 0x00007ffff7af0a2e in PyEval_EvalCodeEx (co=0x7ffff7ecfab0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
    at Python/ceval.c:3582
---Type <return> to continue, or q <return> to quit---
#48 0x00007ffff7af0b42 in PyEval_EvalCode (co=<optimized out>, globals=<optimized out>, locals=<optimized out>) at Python/ceval.c:669
#49 0x00007ffff7b0f5cc in run_mod (arena=0x645f50, flags=<optimized out>, locals=0x7ffff7f6c168, globals=0x7ffff7f6c168, filename=0x7ffff7b3f7ed "<string>", mod=<optimized out>) at Python/pythonrun.c:1370
#50 PyRun_StringFlags (str=0x601010 "import skimage.io; skimage.io.imread(\"segfault.jpg\")\n", start=257, globals=0x7ffff7f6c168, locals=0x7ffff7f6c168, flags=<optimized out>) at Python/pythonrun.c:1333
#51 0x00007ffff7b108f0 in PyRun_SimpleStringFlags (command=0x601010 "import skimage.io; skimage.io.imread(\"segfault.jpg\")\n", flags=0x7fffffffdf90) at Python/pythonrun.c:974
#52 0x00007ffff7b26457 in Py_Main (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:589
#53 0x00007ffff6d3676d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#54 0x0000000000400649 in _start ()
```



Discussion:
```
In [1]: import skimage

In [2]: from skimage import io

In [3]: for plugin in ['matplotlib', 'imageio', 'freeimage', 'pil']:
   ...:     io.use_plugin(plugin)
   ...:     print('Using {}'.format(plugin))
   ...:     img = io.imread('sf.jpg')
   ...:     
Using matplotlib
Using imageio
Using freeimage
/home/egor/workspace/scikit-image/skimage/io/_plugins/freeimage_plugin.py:6: skimage_deprecation: Call to deprecated function ``imread``. Use ``imageio plugin`` instead.
  def imread(filename):
Using pil
*** Error in `/usr/bin/python3': free(): invalid size: 0x0000000002640c10 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x70c4b)[0x7fb190dd6c4b]
/usr/lib/libc.so.6(+0x76fe6)[0x7fb190ddcfe6]
/usr/lib/libc.so.6(+0x777de)[0x7fb190ddd7de]
/usr/lib/libjpeg.so.8(+0x30ce2)[0x7fb1763edce2]
/usr/lib/libjpeg.so.8(+0x30dee)[0x7fb1763eddee]
/usr/lib/libjpeg.so.8(jpeg_destroy+0x10)[0x7fb1763d0f20]
/usr/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-x86_64-linux-gnu.so(ImagingJpegDecode+0x14e)[0x7fb176697f2e]
/usr/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-x86_64-linux-gnu.so(+0x17c97)[0x7fb17667ec97]
/usr/lib/libpython3.6m.so.1.0(_PyCFunction_FastCallDict+0x8f)[0x7fb190968d3f]
/usr/lib/libpython3.6m.so.1.0(+0x14d21f)[0x7fb19095321f]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x317)[0x7fb190914067]
/usr/lib/libpython3.6m.so.1.0(+0x14cd4a)[0x7fb190952d4a]
/usr/lib/libpython3.6m.so.1.0(+0x14d303)[0x7fb190953303]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x317)[0x7fb190914067]
/usr/lib/libpython3.6m.so.1.0(+0x14baa1)[0x7fb190951aa1]
/usr/lib/libpython3.6m.so.1.0(+0x14cf9a)[0x7fb190952f9a]
/usr/lib/libpython3.6m.so.1.0(+0x14d303)[0x7fb190953303]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x317)[0x7fb190914067]
/usr/lib/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x277)[0x7fb190953757]
/usr/lib/libpython3.6m.so.1.0(+0x18c9d3)[0x7fb1909929d3]
/usr/lib/libpython3.6m.so.1.0(PyObject_Call+0x4b)[0x7fb1909cd94b]
/usr/lib/libpython3.6m.so.1.0(+0x1942ce)[0x7fb19099a2ce]
/usr/lib/libpython3.6m.so.1.0(_PyObject_GenericGetAttrWithDict+0x11d)[0x7fb1909a0f1d]
/usr/lib/python3.6/site-packages/numpy/core/multiarray.cpython-36m-x86_64-linux-gnu.so(+0x4e1a6)[0x7fb188a451a6]
/usr/lib/python3.6/site-packages/numpy/core/multiarray.cpython-36m-x86_64-linux-gnu.so(+0x57aee)[0x7fb188a4eaee]
/usr/lib/python3.6/site-packages/numpy/core/multiarray.cpython-36m-x86_64-linux-gnu.so(+0x584f9)[0x7fb188a4f4f9]
/usr/lib/python3.6/site-packages/numpy/core/multiarray.cpython-36m-x86_64-linux-gnu.so(+0x589cd)[0x7fb188a4f9cd]
/usr/lib/python3.6/site-packages/numpy/core/multiarray.cpython-36m-x86_64-linux-gnu.so(+0x58d4d)[0x7fb188a4fd4d]
/usr/lib/python3.6/site-packages/numpy/core/multiarray.cpython-36m-x86_64-linux-gnu.so(+0xda872)[0x7fb188ad1872]
/usr/lib/libpython3.6m.so.1.0(_PyCFunction_FastCallDict+0x12c)[0x7fb190968ddc]
/usr/lib/libpython3.6m.so.1.0(_PyCFunction_FastCallKeywords+0x4d)[0x7fb190968fbd]
/usr/lib/libpython3.6m.so.1.0(+0x14d21f)[0x7fb19095321f]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x1137)[0x7fb190914e87]
/usr/lib/libpython3.6m.so.1.0(+0x14baa1)[0x7fb190951aa1]
/usr/lib/libpython3.6m.so.1.0(+0x14cf9a)[0x7fb190952f9a]
/usr/lib/libpython3.6m.so.1.0(+0x14d303)[0x7fb190953303]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x1137)[0x7fb190914e87]
/usr/lib/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x277)[0x7fb190953757]
/usr/lib/libpython3.6m.so.1.0(+0x18cad5)[0x7fb190992ad5]
/usr/lib/libpython3.6m.so.1.0(PyObject_Call+0x4b)[0x7fb1909cd94b]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x1bf8)[0x7fb190915948]
/usr/lib/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x68f)[0x7fb190953b6f]
/usr/lib/libpython3.6m.so.1.0(+0x18cad5)[0x7fb190992ad5]
/usr/lib/libpython3.6m.so.1.0(PyObject_Call+0x4b)[0x7fb1909cd94b]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x1bf8)[0x7fb190915948]
/usr/lib/libpython3.6m.so.1.0(+0x14baa1)[0x7fb190951aa1]
/usr/lib/libpython3.6m.so.1.0(+0x14cf9a)[0x7fb190952f9a]
/usr/lib/libpython3.6m.so.1.0(+0x14d303)[0x7fb190953303]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x317)[0x7fb190914067]
/usr/lib/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x277)[0x7fb190953757]
/usr/lib/libpython3.6m.so.1.0(PyEval_EvalCode+0x1b)[0x7fb190913d4b]
/usr/lib/libpython3.6m.so.1.0(+0x13cd81)[0x7fb190942d81]
/usr/lib/libpython3.6m.so.1.0(_PyCFunction_FastCallDict+0x8f)[0x7fb190968d3f]
/usr/lib/libpython3.6m.so.1.0(+0x14d21f)[0x7fb19095321f]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x317)[0x7fb190914067]
/usr/lib/libpython3.6m.so.1.0(+0x14baa1)[0x7fb190951aa1]
/usr/lib/libpython3.6m.so.1.0(+0x14cf9a)[0x7fb190952f9a]
/usr/lib/libpython3.6m.so.1.0(+0x14d303)[0x7fb190953303]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x317)[0x7fb190914067]
/usr/lib/libpython3.6m.so.1.0(+0x14baa1)[0x7fb190951aa1]
/usr/lib/libpython3.6m.so.1.0(+0x14cf9a)[0x7fb190952f9a]
/usr/lib/libpython3.6m.so.1.0(+0x14d303)[0x7fb190953303]
/usr/lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x1137)[0x7fb190914e87]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:02 242048                             /usr/bin/python3.6
00601000-00602000 r--p 00001000 08:02 242048                             /usr/bin/python3.6
00602000-00603000 rw-p 00002000 08:02 242048                             /usr/bin/python3.6
016a2000-040a8000 rw-p 00000000 00:00 0                                  [heap]
7fb160000000-7fb160021000 rw-p 00000000 00:00 0 
7fb160021000-7fb164000000 ---p 00000000 00:00 0 
7fb167e9f000-7fb168220000 rw-p 00000000 00:00 0 
7fb168220000-7fb168849000 r-xp 00000000 08:02 159297                     /usr/lib/libQt5Widgets.so.5.7.1
7fb168849000-7fb168a49000 ---p 00629000 08:02 159297                     /usr/lib/libQt5Widgets.so.5.7.1
7fb168a49000-7fb168a76000 r--p 00629000 08:02 159297                     /usr/lib/libQt5Widgets.so.5.7.1
7fb168a76000-7fb168a7b000 rw-p 00656000 08:02 159297                     /usr/lib/libQt5Widgets.so.5.7.1
7fb168a7b000-7fb168abb000 rw-p 00000000 00:00 0 
7fb168abb000-7fb168f6f000 r-xp 00000000 08:02 236241                     /usr/lib/python3.6/site-packages/PyQt5/QtWidgets.so
7fb168f6f000-7fb16916f000 ---p 004b4000 08:02 236241                     /usr/lib/python3.6/site-packages/PyQt5/QtWidgets.so
7fb16916f000-7fb169182000 r--p 004b4000 08:02 236241                     /usr/lib/python3.6/site-packages/PyQt5/QtWidgets.so
7fb169182000-7fb169219000 rw-p 004c7000 08:02 236241                     /usr/lib/python3.6/site-packages/PyQt5/QtWidgets.so
7fb169219000-7fb169259000 rw-p 00000000 00:00 0 
7fb169259000-7fb16925e000 r-xp 00000000 08:02 138301                     /usr/lib/libXdmcp.so.6.0.0
7fb16925e000-7fb16945d000 ---p 00005000 08:02 138301                     /usr/lib/libXdmcp.so.6.0.0
7fb16945d000-7fb16945e000 r--p 00004000 08:02 138301                     /usr/lib/libXdmcp.so.6.0.0
7fb16945e000-7fb16945f000 rw-p 00005000 08:02 138301                     /usr/lib/libXdmcp.so.6.0.0
7fb16945f000-7fb169461000 r-xp 00000000 08:02 138306                     /usr/lib/libXau.so.6.0.0
7fb169461000-7fb169661000 ---p 00002000 08:02 138306                     /usr/lib/libXau.so.6.0.0
7fb169661000-7fb169662000 r--p 00002000 08:02 138306                     /usr/lib/libXau.so.6.0.0
7fb169662000-7fb169663000 rw-p 00003000 08:02 138306                     /usr/lib/libXau.so.6.0.0
7fb169663000-7fb169672000 r-xp 00000000 08:02 142358                     /usr/lib/libdrm.so.2.4.0
7fb169672000-7fb169871000 ---p 0000f000 08:02 142358                     /usr/lib/libdrm.so.2.4.0
7fb169871000-7fb169872000 r--p 0000e000 08:02 142358                     /usr/lib/libdrm.so.2.4.0
7fb169872000-7fb169873000 rw-p 0000f000 08:02 142358                     /usr/lib/libdrm.so.2.4.0
7fb169873000-7fb169878000 r-xp 00000000 08:02 142649                     /usr/lib/libXxf86vm.so.1.0.0
7fb169878000-7fb169a77000 ---p 00005000 08:02 142649                     /usr/lib/libXxf86vm.so.1.0.0
7fb169a77000-7fb169a78000 r--p 00004000 08:02 142649                     /usr/lib/libXxf86vm.so.1.0.0
7fb169a78000-7fb169a79000 rw-p 00005000 08:02 142649                     /usr/lib/libXxf86vm.so.1.0.0
7fb169a79000-7fb169a7d000 r-xp 00000000 08:02 138373                     /usr/lib/libxcb-dri2.so.0.0.0
7fb169a7d000-7fb169c7c000 ---p 00004000 08:02 138373                     /usr/lib/libxcb-dri2.so.0.0.0
7fb169c7c000-7fb169c7d000 r--p 00003000 08:02 138373                     /usr/lib/libxcb-dri2.so.0.0.0
7fb169c7d000-7fb169c7e000 rw-p 00004000 08:02 138373                     /usr/lib/libxcb-dri2.so.0.0.0
7fb169c7e000-7fb169c97000 r-xp 00000000 08:02 138376                     /usr/lib/libxcb-glx.so.0.0.0
7fb169c97000-7fb169e97000 ---p 00019000 08:02 138376                     /usr/lib/libxcb-glx.so.0.0.0
7fb169e97000-7fb169e99000 r--p 00019000 08:02 138376                     /usr/lib/libxcb-glx.so.0.0.0
7fb169e99000-7fb169e9a000 rw-p 0001b000 08:02 138376                     /usr/lib/libxcb-glx.so.0.0.0
7fb169e9a000-7fb169ec2000 r-xp 00000000 08:02 138369                     /usr/lib/libxcb.so.1.1.0
7fb169ec2000-7fb16a0c1000 ---p 00028000 08:02 138369                     /usr/lib/libxcb.so.1.1.0
7fb16a0c1000-7fb16a0c2000 r--p 00027000 08:02 138369                     /usr/lib/libxcb.so.1.1.0
7fb16a0c2000-7fb16a0c3000 rw-p 00028000 08:02 138369                     /usr/lib/libxcb.so.1.1.0
7fb16a0c3000-7fb16a1fc000 r-xp 00000000 08:02 141921                     /usr/lib/libX11.so.6.3.0
7fb16a1fc000-7fb16a3fc000 ---p 00139000 08:02 141921                     /usr/lib/libX11.so.6.3.0
7fb16a3fc000-7fb16a3fd000 r--p 00139000 08:02 141921                     /usr/lib/libX11.so.6.3.0
7fb16a3fd000-7fb16a402000 rw-p 0013a000 08:02 141921                     /usr/lib/libX11.so.6.3.0
7fb16a402000-7fb16a403000 r-xp 00000000 08:02 141922                     /usr/lib/libX11-xcb.so.1.0.0
7fb16a403000-7fb16a602000 ---p 00001000 08:02 141922                     /usr/lib/libX11-xcb.so.1.0.0
7fb16a602000-7fb16a603000 r--p 00000000 08:02 141922                     /usr/lib/libX11-xcb.so.1.0.0
7fb16a603000-7fb16a604000 rw-p 00001000 08:02 141922                     /usr/lib/libX11-xcb.so.1.0.0
7fb16a604000-7fb16a609000 r-xp 00000000 08:02 142654                     /usr/lib/libXfixes.so.3.1.0
7fb16a609000-7fb16a808000 ---p 00005000 08:02 142654                     /usr/lib/libXfixes.so.3.1.0
7fb16a808000-7fb16a809000 r--p 00004000 08:02 142654                     /usr/lib/libXfixes.so.3.1.0
7fb16a809000-7fb16a80a000 rw-p 00005000 08:02 142654                     /usr/lib/libXfixes.so.3.1.0
7fb16a80a000-7fb16a80c000 r-xp 00000000 08:02 142666                     /usr/lib/libXdamage.so.1.1.0
7fb16a80c000-7fb16aa0b000 ---p 00002000 08:02 142666                     /usr/lib/libXdamage.so.1.1.0
7fb16aa0b000-7fb16aa0c000 r--p 00001000 08:02 142666                     /usr/lib/libXdamage.so.1.1.0
7fb16aa0c000-7fb16aa0d000 rw-p 00002000 08:02 142666                     /usr/lib/libXdamage.so.1.1.0
7fb16aa0d000-7fb16aa1e000 r-xp 00000000 08:02 142051                     /usr/lib/libXext.so.6.4.0
7fb16aa1e000-7fb16ac1d000 ---p 00011000 08:02 142051                     /usr/lib/libXext.so.6.4.0
7fb16ac1d000-7fb16ac1e000 r--p 00010000 08:02 142051                     /usr/lib/libXext.so.6.4.0
7fb16ac1e000-7fb16ac1f000 rw-p 00011000 08:02 142051                     /usr/lib/libXext.so.6.4.0
7fb16ac1f000-7fb16ac49000 r-xp 00000000 08:02 211716                     /usr/lib/libglapi.so.0.0.0
7fb16ac49000-7fb16ae48000 ---p 0002a000 08:02 211716                     /usr/lib/libglapi.so.0.0.0
7fb16ae48000-7fb16ae4c000 r--p 00029000 08:02 211716                     /usr/lib/libglapi.so.0.0.0
7fb16ae4c000-7fb16ae4d000 rw-p 0002d000 08:02 211716                     /usr/lib/libglapi.so.0.0.0
7fb16ae4d000-7fb16ae4e000 rw-p 00000000 00:00 0 
7fb16ae4e000-7fb16ae4f000 r-xp 00000000 08:02 142671                     /usr/lib/libxshmfence.so.1.0.0
7fb16ae4f000-7fb16b04f000 ---p 00001000 08:02 142671                     /usr/lib/libxshmfence.so.1.0.0
7fb16b04f000-7fb16b050000 r--p 00001000 08:02 142671                     /usr/lib/libxshmfence.so.1.0.0
7fb16b050000-7fb16b051000 rw-p 00002000 08:02 142671                     /usr/lib/libxshmfence.so.1.0.0
7fb16b051000-7fb16b057000 r-xp 00000000 08:02 138384                     /usr/lib/libxcb-sync.so.1.0.0
7fb16b057000-7fb16b256000 ---p 00006000 08:02 138384                     /usr/lib/libxcb-sync.so.1.0.0
7fb16b256000-7fb16b257000 r--p 00005000 08:02 138384                     /usr/lib/libxcb-sync.so.1.0.0
7fb16b257000-7fb16b258000 rw-p 00006000 08:02 138384                     /usr/lib/libxcb-sync.so.1.0.0
7fb16b258000-7fb16b25a000 r-xp 00000000 08:02 138375                     /usr/lib/libxcb-present.so.0.0.0
7fb16b25a000-7fb16b459000 ---p 00002000 08:02 138375                     /usr/lib/libxcb-present.so.0.0.0
7fb16b459000-7fb16b45a000 r--p 00001000 08:02 138375                     /usr/lib/libxcb-present.so.0.0.0
7fb16b45a000-7fb16b45b000 rw-p 00002000 08:02 138375                     /usr/lib/libxcb-present.so.0.0.0
7fb16b45b000-7fb16b45d000 r-xp 00000000 08:02 138374                     /usr/lib/libxcb-dri3.so.0.0.0
7fb16b45d000-7fb16b65c000 ---p 00002000 08:02 138374                     /usr/lib/libxcb-dri3.so.0.0.0
7fb16b65c000-7fb16b65d000 r--p 00001000 08:02 138374                     /usr/lib/libxcb-dri3.so.0.0.0
7fb16b65d000-7fb16b65e000 rw-p 00002000 08:02 138374                     /usr/lib/libxcb-dri3.so.0.0.0
7fb16b65e000-7fb16b6cc000 r-xp 00000000 08:02 391863                     /usr/lib/mesa/libGL.so.1.2.0
7fb16b6cc000-7fb16b8cb000 ---p 0006e000 08:02 391863                     /usr/lib/mesa/libGL.so.1.2.0
7fb16b8cb000-7fb16b8ce000 r--p 0006d000 08:02 391863                     /usr/lib/mesa/libGL.so.1.2.0
7fb16b8ce000-7fb16b8cf000 rw-p 00070000 08:02 391863                     /usr/lib/mesa/libGL.so.1.2.0
7fb16b8cf000-7fb16b8d0000 rw-p 00000000 00:00 0 
7fb16b8d0000-7fb16bdeb000 r-xp 00000000 08:02 159294                     /usr/lib/libQt5Gui.so.5.7.1
7fb16bdeb000-7fb16bfeb000 ---p 0051b000 08:02 159294                     /usr/lib/libQt5Gui.so.5.7.1
7fb16bfeb000-7fb16bffa000 r--p 0051b000 08:02 159294                     /usr/lib/libQt5Gui.so.5.7.1
7fb16bffa000-7fb16c001000 rw-p 0052a000 08:02 159294                     /usr/lib/libQt5Gui.so.5.7.1
7fb16c001000-7fb16c046000 rw-p 00000000 00:00 0 
7fb16c046000-7fb16c2e8000 r-xp 00000000 08:02 174650                     /usr/lib/python3.6/site-packages/PyQt5/QtGui.so
7fb16c2e8000-7fb16c4e8000 ---p 002a2000 08:02 174650                     /usr/lib/python3.6/site-packages/PyQt5/QtGui.so
7fb16c4e8000-7fb16c4ff000 r--p 002a2000 08:02 174650                     /usr/lib/python3.6/site-packages/PyQt5/QtGui.so
7fb16c4ff000-7fb16c56c000 rw-p 002b9000 08:02 174650                     /usr/lib/python3.6/site-packages/PyQt5/QtGui.so
7fb16c56c000-7fb16c57f000 r-xp 00000000 08:02 227068                     /usr/lib/libgpg-error.so.0.21.0
7fb16c57f000-7fb16c77e000 ---p 00013000 08:02 227068                     /usr/lib/libgpg-error.so.0.21.0
7fb16c77e000-7fb16c77f000 r--p 00012000 08:02 227068                     /usr/lib/libgpg-error.so.0.21.0
7fb16c77f000-7fb16c780000 rw-p 00013000 08:02 227068                     /usr/lib/libgpg-error.so.0.21.0
7fb16c780000-7fb16c887000 r-xp 00000000 08:02 157010                     /usr/lib/libgcrypt.so.20.1.5
7fb16c887000-7fb16ca86000 ---p 00107000 08:02 157010                     /usr/lib/libgcrypt.so.20.1.5
7fb16ca86000-7fb16ca88000 r--p 00106000 08:02 157010                     /usr/lib/libgcrypt.so.20.1.5
7fb16ca88000-7fb16ca8f000 rw-p 00108000 08:02 157010                     /usr/lib/libgcrypt.so.20.1.5
7fb16ca8f000-7fb16caa0000 r-xp 00000000 08:02 137015                     /usr/lib/liblz4.so.1.7.4
7fb16caa0000-7fb16cc9f000 ---p 00011000 08:02 137015                     /usr/lib/liblz4.so.1.7.4
7fb16cc9f000-7fb16cca0000 r--p 00010000 08:02 137015                     /usr/lib/liblz4.so.1.7.4
7fb16cca0000-7fb16cca1000 rw-p 00011000 08:02 137015                     /usr/lib/liblz4.so.1.7.4
7fb16cca1000-7fb16cca5000 r-xp 00000000 08:02 133893                     /usr/lib/libcap.so.2.25
7fb16cca5000-7fb16cea4000 ---p 00004000 08:02 133893                     /usr/lib/libcap.so.2.25
7fb16cea4000-7fb16cea5000 rw-p 00003000 08:02 133893                     /usr/lib/libcap.so.2.25
7fb16cea5000-7fb16ceb9000 r-xp 00000000 08:02 133617                     /usr/lib/libresolv-2.24.so
7fb16ceb9000-7fb16d0b8000 ---p 00014000 08:02 133617                     /usr/lib/libresolv-2.24.so
7fb16d0b8000-7fb16d0b9000 r--p 00013000 08:02 133617                     /usr/lib/libresolv-2.24.so
7fb16d0b9000-7fb16d0ba000 rw-p 00014000 08:02 133617                     /usr/lib/libresolv-2.24.so
7fb16d0ba000-7fb16d0bc000 rw-p 00000000 00:00 0 
7fb16d0bc000-7fb16e9bc000 r--p 00000000 08:02 169517                     /usr/lib/libicudata.so.58.2
7fb16e9bc000-7fb16ebbb000 ---p 01900000 08:02 169517                     /usr/lib/libicudata.so.58.2
7fb16ebbb000-7fb16ebbc000 r--p 018ff000 08:02 169517                     /usr/lib/libicudata.so.58.2
7fb16ebbc000-7fb16ec40000 r-xp 00000000 08:02 198181                     /usr/lib/libsystemd.so.0.17.0
7fb16ec40000-7fb16ec43000 r--p 00083000 08:02 198181                     /usr/lib/libsystemd.so.0.17.0
7fb16ec43000-7fb16ec44000 rw-p 00086000 08:02 198181                     /usr/lib/libsystemd.so.0.17.0
7fb16ec44000-7fb16ec45000 rw-p 00000000 00:00 0 
7fb16ec45000-7fb16ec4c000 r-xp 00000000 08:02 133618                     /usr/lib/librt-2.24.so
7fb16ec4c000-7fb16ee4b000 ---p 00007000 08:02 133618                     /usr/lib/librt-2.24.so
7fb16ee4b000-7fb16ee4c000 r--p 00006000 08:02 133618                     /usr/lib/librt-2.24.so
7fb16ee4c000-7fb16ee4d000 rw-p 00007000 08:02 133618                     /usr/lib/librt-2.24.so
7fb16ee4d000-7fb16eeb5000 r-xp 00000000 08:02 137043                     /usr/lib/libpcre16.so.0.2.7
7fb16eeb5000-7fb16f0b4000 ---p 00068000 08:02 137043                     /usr/lib/libpcre16.so.0.2.7
7fb16f0b4000-7fb16f0b5000 r--p 00067000 08:02 137043                     /usr/lib/libpcre16.so.0.2.7
7fb16f0b5000-7fb16f0b6000 rw-p 00068000 08:02 137043                     /usr/lib/libpcre16.so.0.2.7
7fb16f0b6000-7fb16f24e000 r-xp 00000000 08:02 169528                     /usr/lib/libicuuc.so.58.2
7fb16f24e000-7fb16f44e000 ---p 00198000 08:02 169528                     /usr/lib/libicuuc.so.58.2
7fb16f44e000-7fb16f460000 r--p 00198000 08:02 169528                     /usr/lib/libicuuc.so.58.2
7fb16f460000-7fb16f461000 rw-p 001aa000 08:02 169528                     /usr/lib/libicuuc.so.58.2
7fb16f461000-7fb16f462000 rw-p 00000000 00:00 0 
7fb16f462000-7fb16f6cd000 r-xp 00000000 08:02 169529                     /usr/lib/libicui18n.so.58.2
7fb16f6cd000-7fb16f8cc000 ---p 0026b000 08:02 169529                     /usr/lib/libicui18n.so.58.2
7fb16f8cc000-7fb16f8d9000 r--p 0026a000 08:02 169529                     /usr/lib/libicui18n.so.58.2
7fb16f8d9000-7fb16f8db000 rw-p 00277000 08:02 169529                     /usr/lib/libicui18n.so.58.2
7fb16f8db000-7fb16f8dc000 rw-p 00000000 00:00 0 
7fb16f8dc000-7fb16fda3000 r-xp 00000000 08:02 159288                     /usr/lib/libQt5Core.so.5.7.1
7fb16fda3000-7fb16ffa3000 ---p 004c7000 08:02 159288                     /usr/lib/libQt5Core.so.5.7.1
7fb16ffa3000-7fb16ffaf000 r--p 004c7000 08:02 159288                     /usr/lib/libQt5Core.so.5.7.1
7fb16ffaf000-7fb16ffb0000 rw-p 004d3000 08:02 159288                     /usr/lib/libQt5Core.so.5.7.1
7fb16ffb0000-7fb16fff4000 rw-p 00000000 00:00 0 
7fb16fff4000-7fb170259000 r-xp 00000000 08:02 174649                     /usr/lib/python3.6/site-packages/PyQt5/QtCore.so
7fb170259000-7fb170459000 ---p 00265000 08:02 174649                     /usr/lib/python3.6/site-packages/PyQt5/QtCore.so
7fb170459000-7fb17045d000 r--p 00265000 08:02 174649                     /usr/lib/python3.6/site-packages/PyQt5/QtCore.so
7fb17045d000-7fb1704c3000 rw-p 00269000 08:02 174649                     /usr/lib/python3.6/site-packages/PyQt5/QtCore.so
7fb1704c3000-7fb1704df000 r-xp 00000000 08:02 174645                     /usr/lib/python3.6/site-packages/sip.so
7fb1704df000-7fb1706df000 ---p 0001c000 08:02 174645                     /usr/lib/python3.6/site-packages/sip.so
7fb1706df000-7fb1706e0000 r--p 0001c000 08:02 174645                     /usr/lib/python3.6/site-packages/sip.so
7fb1706e0000-7fb1706e2000 rw-p 0001d000 08:02 174645                     /usr/lib/python3.6/site-packages/sip.so
7fb1706e2000-7fb170722000 rw-p 00000000 00:00 0 
7fb170722000-7fb170764000 r-xp 00000000 08:02 236853                     /usr/lib/python3.6/site-packages/matplotlib/backends/_backend_agg.cpython-36m-x86_64-linux-gnu.so
7fb170764000-7fb170963000 ---p 00042000 08:02 236853                     /usr/lib/python3.6/site-packages/matplotlib/backends/_backend_agg.cpython-36m-x86_64-linux-gnu.so
7fb170963000-7fb170964000 r--p 00041000 08:02 236853                     /usr/lib/python3.6/site-packages/matplotlib/backends/_backend_agg.cpython-36m-x86_64-linux-gnu.so
7fb170964000-7fb170965000 rw-p 00042000 08:02 236853                     /usr/lib/python3.6/site-packages/matplotlib/backends/_backend_agg.cpython-36m-x86_64-linux-gnu.so
7fb170965000-7fb170a66000 rw-p 00000000 00:00 0 
7fb170a66000-7fb170ac0000 r-xp 00000000 08:02 236463                     /usr/lib/python3.6/site-packages/matplotlib/_qhull.cpython-36m-x86_64-linux-gnu.so
7fb170ac0000-7fb170cc0000 ---p 0005a000 08:02 236463                     /usr/lib/python3.6/site-packages/matplotlib/_qhull.cpython-36m-x86_64-linux-gnu.so
7fb170cc0000-7fb170cc1000 r--p 0005a000 08:02 236463                     /usr/lib/python3.6/site-packages/matplotlib/_qhull.cpython-36m-x86_64-linux-gnu.so
7fb170cc1000-7fb170cc2000 rw-p 0005b000 08:02 236463                     /usr/lib/python3.6/site-packages/matplotlib/_qhull.cpython-36m-x86_64-linux-gnu.so
7fb170cc2000-7fb170cc4000 rw-p 00000000 00:00 0 
7fb170cc4000-7fb170cdb000 r-xp 00000000 08:02 236462                     /usr/lib/python3.6/site-packages/matplotlib/_tri.cpython-36m-x86_64-linux-gnu.so
7fb170cdb000-7fb170edb000 ---p 00017000 08:02 236462                     /usr/lib/python3.6/site-packages/matplotlib/_tri.cpython-36m-x86_64-linux-gnu.so
7fb170edb000-7fb170edc000 r--p 00017000 08:02 236462                     /usr/lib/python3.6/site-packages/matplotlib/_tri.cpython-36m-x86_64-linux-gnu.so
7fb170edc000-7fb170edd000 rw-p 00018000 08:02 236462                     /usr/lib/python3.6/site-packages/matplotlib/_tri.cpython-36m-x86_64-linux-gnu.so
7fb170edd000-7fb170fdd000 rw-p 00000000 00:00 0 
7fb170fdd000-7fb171000000 r-xp 00000000 08:02 236469                     /usr/lib/python3.6/site-packages/matplotlib/_image.cpython-36m-x86_64-linux-gnu.so
7fb171000000-7fb171200000 ---p 00023000 08:02 236469                     /usr/lib/python3.6/site-packages/matplotlib/_image.cpython-36m-x86_64-linux-gnu.so
7fb171200000-7fb171201000 r--p 00023000 08:02 236469                     /usr/lib/python3.6/site-packages/matplotlib/_image.cpython-36m-x86_64-linux-gnu.so
7fb171201000-7fb171202000 rw-p 00024000 08:02 236469                     /usr/lib/python3.6/site-packages/matplotlib/_image.cpython-36m-x86_64-linux-gnu.so
7fb171202000-7fb1712c3000 rw-p 00000000 00:00 0 
7fb1712c3000-7fb1712d0000 r-xp 00000000 08:02 236465                     /usr/lib/python3.6/site-packages/matplotlib/_contour.cpython-36m-x86_64-linux-gnu.so
7fb1712d0000-7fb1714d0000 ---p 0000d000 08:02 236465                     /usr/lib/python3.6/site-packages/matplotlib/_contour.cpython-36m-x86_64-linux-gnu.so
7fb1714d0000-7fb1714d1000 r--p 0000d000 08:02 236465                     /usr/lib/python3.6/site-packages/matplotlib/_contour.cpython-36m-x86_64-linux-gnu.so
7fb1714d1000-7fb1714d2000 rw-p 0000e000 08:02 236465                     /usr/lib/python3.6/site-packages/matplotlib/_contour.cpython-36m-x86_64-linux-gnu.so
7fb1714d2000-7fb1714d7000 r-xp 00000000 08:02 236466                     /usr/lib/python3.6/site-packages/matplotlib/_cntr.cpython-36m-x86_64-linux-gnu.so
7fb1714d7000-7fb1716d7000 ---p 00005000 08:02 236466                     /usr/lib/python3.6/site-packages/matplotlib/_cntr.cpython-36m-x86_64-linux-gnu.so
7fb1716d7000-7fb1716d8000 r--p 00005000 08:02 236466                     /usr/lib/python3.6/site-packages/matplotlib/_cntr.cpython-36m-x86_64-linux-gnu.so
7fb1716d8000-7fb1716d9000 rw-p 00006000 08:02 236466                     /usr/lib/python3.6/site-packages/matplotlib/_cntr.cpython-36m-x86_64-linux-gnu.so
7fb1716d9000-7fb171719000 rw-p 00000000 00:00 0 
7fb171719000-7fb17171f000 r-xp 00000000 08:02 236470                     /usr/lib/python3.6/site-packages/matplotlib/_png.cpython-36m-x86_64-linux-gnu.so
7fb17171f000-7fb17191e000 ---p 00006000 08:02 236470                     /usr/lib/python3.6/site-packages/matplotlib/_png.cpython-36m-x86_64-linux-gnu.so
7fb17191e000-7fb17191f000 r--p 00005000 08:02 236470                     /usr/lib/python3.6/site-packages/matplotlib/_png.cpython-36m-x86_64-linux-gnu.so
7fb17191f000-7fb171920000 rw-p 00006000 08:02 236470                     /usr/lib/python3.6/site-packages/matplotlib/_png.cpython-36m-x86_64-linux-gnu.so
7fb171920000-7fb171960000 rw-p 00000000 00:00 0 
7fb171960000-7fb1719d2000 r-xp 00000000 08:02 137042                     /usr/lib/libpcre.so.1.2.7
7fb1719d2000-7fb171bd1000 ---p 00072000 08:02 137042                     /usr/lib/libpcre.so.1.2.7
7fb171bd1000-7fb171bd2000 r--p 00071000 08:02 137042                     /usr/lib/libpcre.so.1.2.7
7fb171bd2000-7fb171bd3000 rw-p 00072000 08:02 137042                     /usr/lib/libpcre.so.1.2.7
7fb171bd3000-7fb171bfd000 r-xp 00000000 08:02 142056                     /usr/lib/libgraphite2.so.3.0.1
7fb171bfd000-7fb171dfc000 ---p 0002a000 08:02 142056                     /usr/lib/libgraphite2.so.3.0.1
7fb171dfc000-7fb171dfe000 r--p 00029000 08:02 142056                     /usr/lib/libgraphite2.so.3.0.1
7fb171dfe000-7fb171dff000 rw-p 0002b000 08:02 142056                     /usr/lib/libgraphite2.so.3.0.1Aborted (core dumped)
```

Reading with PIL
-----------------
```
In [7]: from PIL import Image
In [8]: img = Image.open('sf.jpg')
In [9]: img
Out[9]: <PIL.MpoImagePlugin.MpoImageFile image mode=RGB size=1600x1064 at 0x7F27BD6FD7F0>
In [10]: import numpy as np
In [11]: img_arr = np.array(img)
In [12]: img_arr.shape
Out[12]: (1064, 1600, 3)
```

Versions
---------
```
In [2]: import PIL, matplotlib, imageio, skimage
In [3]: PIL.VERSION
Out[3]: '1.1.7'
In [4]: matplotlib.__version__
Out[4]: '1.5.3'
In [5]: imageio.__version__
Out[5]: '2.1.1'
In [6]: skimage.__version__
Out[6]: '0.13dev'
```

Potentially, a flaw of our PIL wrapper.
I can't reproduce this, my call to `io.imread` after calling `io.use_plugin('pil')` works just fine (as did `io.imread("im.jpg", plugin="pil")` for good measure. 

Image downloaded using link above. 

 I also have 

```
In [1]: import PIL, matplotlib, imageio, skimage
In [2]: PIL.VERSION
Out[2]: '1.1.7'
In [3]: matplotlib.__version__
Out[3]: '1.5.3'
In [4]: imageio.__version__
Out[4]: '1.4'
In [5]: skimage.__version__
Out[5]: '0.13dev'
```

(but I doubt my lower `imageio` was the culprit). 

I'm on Python 3.4.3 and  on 3.13.0-61-generic #100-Ubuntu SMP Wed Jul 29 11:21:34 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Unfortunately, in the meantime, this issue has now also appeared on my machine :( 

However, it only occurs from `skimage.io` when using the `PIL` plugin, not from using `PIL` alone. 

Code to reproduce: 

```python
fname = "bad_image.jpg"
import PIL
import PIL.Image
import skimage
import skimage.io
import numpy as np
print("Skimage version :", skimage.__version__)
print("PIL version     :", PIL.__version__)

print("Trying to use PIL...", flush=True)
try:
    im = PIL.Image.open(fname)
    print("PIL Image size:", im.size)
    arr = np.array(im)
    print("Array size:", arr.shape)
except:
    print("Issue in PIL")
    raise

print("PIL was fine", flush=True)
print("Trying to use skimage...", flush=True)
try:
    im = skimage.io.imread(fname, plugin='pil')
except:
    print("Issue in Skimage")
    raise
```

Produces: 

```
Skimage version : 0.14dev
PIL version     : 5.1.0
Trying to use PIL...
PIL Image size: (1600, 1064)
Array size: (1064, 1600, 3)
PIL was fine
Trying to use skimage...
[1]    11201 segmentation fault  py test.py
```
I've played around with `pil_to_ndarray` and can now confirm that the issue is that on the "bad file", the second attempt to seek passes ( https://github.com/scikit-image/scikit-image/blob/master/skimage/io/_plugins/pil_plugin.py#L67 ) i.e. when i=1, which it should not as it's a single image. 

This may reveal an issue with the jpeg encoding but essentially this wrapper function should be able to handle such files I would think. 

I'll work on a fix and push once ready. 
Tracked down the issue from `PIL`, which is *kind of* an issue with JPEGs, but something that (as mentioned in that issue) `PIL` should be able to handle... 

https://github.com/python-pillow/Pillow/issues/1631

A simple, though not very satisfactory fix, would be to test the filename extension; if it's "jpg", then restrict to single frame...thoughts? 


For anyone concerned - the above image **does** contain two frames and I succeeded in reading in both (see my comment and code on https://github.com/python-pillow/Pillow/issues/1631 ) - the issue is just that PIL's support of MPO files (which this is) is a little immature and doesn't work properly yet on this image.

Any thoughts on how best to handle this here in the meantime? 
Since this will be fixed sometime in the future (one hopes!), can we try and detect when MPOs are being loaded, and warn that PIL may cause a segfault, and suggest a workaround (i.e. reading in frame №1 with `matplotlib` or `imageio`)?  Unless `imageio` supports correctly reading MPOs, in which case we should just error and refer the user there.
AFAIK, both `matplotlib` (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imread.html) and `imageio` also use `PIL` to read JPEGs.

However, the way in which they do so doesn't seem to attempt to seek (i.e. unlike `skimage.io` they don't try and load multiple frames using `n_frames` on the `PIL` `Image` object) , so they are more stable in that respect. 
We could just switch to `imageio` or `matplotlib` becoming the default handler for JPEGs...?
@jmetz we are going to make a transition to `imageio` in the near future - https://github.com/scikit-image/scikit-image/issues/1605 .
For now, I personally like the idea of @stefanv on detecting MPOs and raising a warning.
@soupault  - sounds good, though just to reiterate - `imageio` doesn't really fix this - the only difference is that `imread` in `imageio`, by default, only reads one frame of data (see https://github.com/imageio/imageio/blob/master/imageio/core/functions.py#L207 ), as opposed to the current `skimage.io.imread` which attempts to read all frames of data, so I wouldn't consider this as a solution.  

(i.e. they both rely on the buggy PIL MPO reader...)
I think I have fixed this in PIL: https://github.com/python-pillow/Pillow/pull/3126 
If that works and is accepted by the folks there, then this should fix the issue for all libraries that use PIL to read MPOs :) 

@jmetz awesome, any idea how far back it would be backported?
@hmaarrfk - No idea :man_shrugging: it's not been merged into `pillow` yet. 
The issue has just been fixed upstream. What would be our course of actions here?
Based on the changelog, it must be fixed in PIL 6.0.0 released in April 2019. Either we warn users to upgrade to this version if they use MPO, either we update the min version. I prefer the second solution.

Resolving patch:
diff --git a/skimage/io/_plugins/pil_plugin.py b/skimage/io/_plugins/pil_plugin.py
--- a/skimage/io/_plugins/pil_plugin.py
+++ b/skimage/io/_plugins/pil_plugin.py
@@ -1,7 +1,9 @@
 __all__ = ['imread', 'imsave']
 
+from distutils.version import LooseVersion
+import warnings
 import numpy as np
-from PIL import Image
+from PIL import Image, __version__ as pil_version
 
 from ...util import img_as_ubyte, img_as_uint
 
@@ -36,6 +38,11 @@ def imread(fname, dtype=None, img_num=None, **kwargs):
             return pil_to_ndarray(im, dtype=dtype, img_num=img_num)
     else:
         im = Image.open(fname)
+        if im.format == 'MPO' and LooseVersion(pil_version) < '6.0.0':
+            warnings.warn("You are trying to read a MPO image. "
+                          "To ensure a good support of this format, "
+                          "please upgrade pillow to 6.0.0 version or later.",
+                          stacklevel=2)
         return pil_to_ndarray(im, dtype=dtype, img_num=img_num)
 
 


Test patch: