Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#24948 closed Bug (fixed)

BMP Image File treated as invalid

Reported by: jerzyk Owned by: Andriy Sokolovskiy
Component: Forms Version: 1.8
Severity: Release blocker Keywords: bmp, image
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

when assigning a .bmp (windows bitmap) image to an ImageField field, django reports error, responsible line, that raises an error is django/forms/fields.py:695 (to_python)

f.content_type = Image.MIME[image.format]

file is validated properly (opened, validated) and at the and, it's mime_type is detected by using a dictionary Image.MIME.

This dictionary is not documented and does not contain entries for BMP file, so it may be assumed that Django is using it's private api.

There are two options - push on Pillow to make this public API and fix an issue or use different method to find mime-type (e.g. python's standard mimetypes library)

Change History (5)

comment:1 Changed 5 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

It's a regression in 1.8 (#10935), so qualifies for a backport. At least we could catch the exception and set f.content_type = None in that case.

comment:2 Changed 5 years ago by Andriy Sokolovskiy

Has patch: set
Owner: changed from nobody to Andriy Sokolovskiy
Status: newassigned

https://github.com/django/django/pull/4869

I think setting content_type to None will be enough.

comment:3 Changed 5 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:4 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In cf6ce279:

Fixed #24948 -- Fixed crash when uploading bitmap images in forms.ImageField

comment:5 Changed 5 years ago by Tim Graham <timograham@…>

In 8abe2d0:

[1.8.x] Fixed #24948 -- Fixed crash when uploading bitmap images in forms.ImageField

Backport of cf6ce279c7671a4c83c960c5c526f92679a4fac8 from master

Note: See TracTickets for help on using tickets.
Back to Top