jdriscoll/django-imagekit — Issue #84: Segmentation fault in AutoConvert.process for GIF images
Author: mkai
Created: 2012-01-19 12:08:23+00:00
State: open

I noticed that the Django dev server crashes on my system when I save a GIF file to an ImageField that has imagekit configured. After some print debugging, I found the culprit in the ``AutoConvert`` processor:

```python
def process(self, img):
matte = False
self.save_kwargs = {}
print('**** img.mode: %s' % img.mode)
if img.mode == 'RGBA':
if self.format in RGBA_TRANSPARENCY_FORMATS:
pass
elif self.format in PALETTE_TRANSPARENCY_FORMATS:
# [comment stripped]
alpha = img.split()[-1]
mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
print('**** converting RGB')
img = img.convert('RGB')
print('**** converting P')
img = img.convert('P', palette=Image.ADAPTIVE, colors=255) # this statement segfaults
print('**** converting done')
img.paste(255, mask)
self.save_kwargs['transparency'] = 255
else:
# [...]

```

I took the two ``convert`` statements apart in the code above.

When the image is first processed, i. e. right after upload, the output is:

```
**** img.mode: P
**** img.mode: RGBA
**** converting RGB
**** converting P
2009 Segmentation fault: 11 python manage.py runserver
```

So it looks like the segmentation fault occurs when an RGBA GIF image is converted from RGBA to RGB to P.

Do you have an idea what could cause the problem?

I have worked around this for now using ``autoconvert=False``.