Opened 14 years ago

Closed 12 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: dev
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 14 years ago.
revisedtest.diff (882 bytes ) - added by Brett Haydon 14 years ago.
14681_unified.diff (1.6 KB ) - added by dmclain 14 years ago.
unified the two patches and fixed a bug in one of the tests

Download all attachments as: .zip

Change History (10)

by Brad Greenlee, 14 years ago

Attachment: django_mode_patch.diff added

by Brett Haydon, 14 years ago

Attachment: revisedtest.diff added

comment:1 by Brett Haydon, 14 years ago

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 by James Addison, 14 years ago

milestone: 1.3
Severity: Normal
Type: Bug

comment:3 by patchhammer, 14 years ago

Easy pickings: unset
Patch needs improvement: set

revisedtest.diff fails to apply cleanly on to trunk

by dmclain, 14 years ago

Attachment: 14681_unified.diff added

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

comment:4 by dmclain, 14 years ago

Patch needs improvement: unset

comment:5 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Moritz Sichert, 13 years ago

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

comment:7 by Claude Paroz <claude@…>, 12 years ago

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