Opened 6 years ago

Closed 5 years ago

#14681 closed Bug (fixed)

Uploaded files should not set mode to None

Reported by: Brad Greenlee Owned by: Brett Haydon
Component: File uploads/storage Version: master
Severity: Normal Keywords: sprintdec2010
Cc: moritz.sichert@… 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

I ran across this issue when attempting to open an uploaded file with GzipFile(fileobj=uploaded_file). If you don't pass in the mode parameter as well, GzipFile crashes. GzipFile looks to see if the fileobj has a mode attribute, and if it does, it uses it; however, using a mode of None causes it to crash.

I filed a bug and patch for GzipFile (http://bugs.python.org/issue10392), but it was rejected, saying that the bug was in Django for setting the mode on the file to None. So I've attached a patch (with test) to django.core.files.base.File that only sets mode if mode is present.

Attachments (3)

django_mode_patch.diff (1.1 KB) - added by Brad Greenlee 6 years ago.
revisedtest.diff (882 bytes) - added by Brett Haydon 6 years ago.
14681_unified.diff (1.6 KB) - added by dmclain 6 years ago.
unified the two patches and fixed a bug in one of the tests

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by Brad Greenlee

Attachment: django_mode_patch.diff added

Changed 6 years ago by Brett Haydon

Attachment: revisedtest.diff added

comment:1 Changed 6 years ago by Brett Haydon

Keywords: sprintdec2010 added
milestone: 1.3
Owner: changed from nobody to Brett Haydon
Status: newassigned
Triage Stage: UnreviewedAccepted

Added a revised test patch to explicity test against stdlib gzip.Gzip which is the point of failure.

To expand, python expects the mode attr to be from the usual 'r','w' etc list or not set at all on a file like object.

comment:2 Changed 6 years ago by James Addison

milestone: 1.3
Severity: Normal
Type: Bug

comment:3 Changed 6 years ago by patchhammer

Easy pickings: unset
Patch needs improvement: set

revisedtest.diff fails to apply cleanly on to trunk

Changed 6 years ago by dmclain

Attachment: 14681_unified.diff added

unified the two patches and fixed a bug in one of the tests

comment:4 Changed 6 years ago by dmclain

Patch needs improvement: unset

comment:5 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 5 years ago by Moritz Sichert

Cc: moritz.sichert@… added
Triage Stage: AcceptedReady for checkin

comment:7 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In [2626ea4a74d09642a50c3fb30944513b68dda289]:

Fixed #14681 -- Do not set mode to None on file-like objects.

gzip.GzipFile does not support files with mode set to None.

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