[issue10392] GZipFile crash when fileobj.mode is None
New submission from Brad Greenlee : 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 <http://bugs.python.org/issue10392> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10392] GZipFile crash when fileobj.mode is None
Brad Greenlee added the comment: GzipFile.__init__ considers mode == None to be the equivalent of undefined, and sets it to the default of 'rb'. I see fileobj.mode == None as the same thing. That said, it is probably a bug in Django as well; I'll look into that. I still think that GzipFile should handle this gracefully. -- status: pending -> open ___ Python tracker <http://bugs.python.org/issue10392> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10392] GZipFile crash when fileobj.mode is None
Brad Greenlee added the comment: Yes, but if I actually passed mode=None in, the behavior would be the same, no? -- ___ Python tracker <http://bugs.python.org/issue10392> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10392] GZipFile crash when fileobj.mode is None
Brad Greenlee added the comment: Understood. I just felt that fileobj.mode == None should be handled the same way that GzipFile(...,mode=None) is handled. I've submitted a patch to Django: http://code.djangoproject.com/ticket/14681 -- ___ Python tracker <http://bugs.python.org/issue10392> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com