﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30252	ImageField's to_python() stores reference to closed Image object	Felix Dreissig	Hasan Ramezani	"In django.forms.fields.ImageField's `to_python()` method, an uploaded image is validated by `open()`ing a PIL.Image object from it and calling `verify()` on that. Afterwards, the Image object is saved to an `image` attribute of the uploaded file (i.e. an InMemoryUploadedFile). According to a comment in the source, this happens so that ""subclasses can reuse it for their own validation"".

Pillow closes an Image after `verify()`ing and the docs [https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.verify state] that it cannot be used after calling `verify` on it:

  If you need to load the image after using this method, you must reopen the image file.

For me, this resulted in the following error when trying to explicitly call `save()` on the Image, but similar effects will probably happen for any operation:

{{{
  File "".../lib/python3.6/site-packages/PIL/Image.py"", line 1960, in save
    self.load()
  File "".../lib/python3.6/site-packages/PIL/ImageFile.py"", line 165, in load
    seek = self.fp.seek
AttributeError: 'NoneType' object has no attribute 'seek'
}}}

This could be related to #13750, but I don't think so."	Cleanup/optimization	closed	Documentation	dev	Normal	fixed			Accepted	1	0	0	0	0	0
