[New-bugs-announce] [issue10392] GZipFile crash when fileobj.mode is None

Brad Greenlee report at bugs.python.org
Fri Nov 12 06:58:44 CET 2010

New submission from Brad Greenlee <brad at footle.org>:

If GZipFile.__init_ is passed a fileobj that has a mode attribute set to None, it will crash with a "'NoneType' object is unsubscriptable" error when it tries to read the first character of the mode.

I ran across this when trying to pass GZipFile an uploaded file in Django 1.2.3. Django produced an InMemoryUploadedFile object that has a mode attribute set to None.

The attached patch fixes the issue by only using fileobj.mode if it exists and is not None.

(The patch is against 2.7, although the issue exists in all versions I've looked at.)

components: Library (Lib)
files: gzip_mode_fix.diff
keywords: patch
messages: 121021
nosy: bgreenlee
priority: normal
severity: normal
status: open
title: GZipFile crash when fileobj.mode is None
type: crash
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file19576/gzip_mode_fix.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list