Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2eb478

Browse files
committed
[1.3.x] Fixed second security issue in image uploading. Disclosure and release forthcoming.
Backport of b1d4634 from master.
1 parent 9ca0ff6 commit b2eb478

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

django/forms/fields.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -538,20 +538,10 @@ def to_python(self, data):
538538
file = StringIO(data['content'])
539539

540540
try:
541-
# load() is the only method that can spot a truncated JPEG,
542-
# but it cannot be called sanely after verify()
543-
trial_image = Image.open(file)
544-
trial_image.load()
545-
546-
# Since we're about to use the file again we have to reset the
547-
# file object if possible.
548-
if hasattr(file, 'reset'):
549-
file.reset()
550-
551-
# verify() is the only method that can spot a corrupt PNG,
552-
# but it must be called immediately after the constructor
553-
trial_image = Image.open(file)
554-
trial_image.verify()
541+
# load() could spot a truncated JPEG, but it loads the entire
542+
# image in memory, which is a DoS vector. See #3848 and #18520.
543+
# verify() must be called immediately after the constructor.
544+
Image.open(file).verify()
555545
except ImportError:
556546
# Under PyPy, it is possible to import PIL. However, the underlying
557547
# _imaging C module isn't available, so an ImportError will be

0 commit comments

Comments
 (0)