classification
Title: zipfile: Bad error message when zipping a file with timestamp before 1980
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ced, ezio.melotti, ivb, loewis, mark.dickinson, orsenthil, petri.lehtinen, python-dev, r.david.murray, techtonik
Priority: normal Keywords: needs review, patch

Created on 2009-05-22 16:50 by ivb, last changed 2011-10-19 17:54 by orsenthil. This issue is now closed.

Files
File name Uploaded Description Edit
test6090.py techtonik, 2010-04-06 07:54
zipfile_timestamps_before_1980.patch petri.lehtinen, 2011-07-06 20:29
Messages (8)
msg88201 - (view) Author: Ivan Bykov (ivb) Date: 2009-05-22 16:50
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit 
(Intel)] on win32
IDLE 2.6.2      
>>> import zipfile
>>> new = zipfile.ZipFile('C:\\x', 'w', zipfile.ZIP_DEFLATED)
>>> zi = zipfile.ZipInfo('test',(1,2,3,4,5,6))
>>> new.writestr(zi,'fgh')

Warning (from warnings module):
  File "H:\programs\python\lib\zipfile.py", line 1105
    self.fp.write(zinfo.FileHeader())
DeprecationWarning: struct integer overflow masking is deprecated

Warning (from warnings module):
  File "H:\programs\python\lib\zipfile.py", line 1105
    self.fp.write(zinfo.FileHeader())
DeprecationWarning: 'H' format requires 0 <= number <= 65535
>>>
msg102437 - (view) Author: anatoly techtonik (techtonik) Date: 2010-04-06 07:54
This code is broken in 2.7alpha4 - it doesn't add file at all.

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    new.writestr(zi,'fgh')
  File "C:\~env\Python27\lib\zipfile.py", line 1099, in writestr
    self.fp.write(zinfo.FileHeader())
  File "C:\~env\Python27\lib\zipfile.py", line 342, in FileHeader
    len(filename), len(extra))
struct.error: ushort format requires 0 <= number <= USHRT_MAX
msg102461 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-04-06 12:33
Making the stage test needed, since we need to get the test into the test suite as a unit test.
msg102534 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-04-07 11:14
This is not a bug in the code, but in the application. You are passing a date before 1980; this is not supported in zipfiles. Try passing 1980 instead of 1.

I think the error message could be better, though; it should probably be a ValueError.

Reducing the priority to normal.
msg103024 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-13 09:13
[Martin]
> I think the error message could be better, though; it should probably be a ValueError.

Do you mean a ValueError at the level of the struct module, or the zipfile module.

I'd quite like to change all the exceptions raised by the struct module to ValueError or TypeError (as appropriate);  I'm not sure what the point of struct.error is supposed to be.  I've resisted making this change up until now for backwards compatibility reasons, but perhaps it could be considered for 3.2 (but not for 2.7).
msg139950 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-07-06 20:29
Retitled to reflect that the error message should be enhanced.

Attached a patch for 2.7 that raises ValueError for timestamps before 1980, documents that 1980 or later is required, and adds some tests.
msg145925 - (view) Author: Roundup Robot (python-dev) Date: 2011-10-19 17:53
New changeset 649ac338203f by Senthil Kumaran in branch '2.7':
Fix closes Issue6090 - Raise a ValueError, instead of failing with unrelated
http://hg.python.org/cpython/rev/649ac338203f

New changeset 12f3e86e9041 by Senthil Kumaran in branch '3.2':
3.2 - Fix closes Issue6090 - Raise a ValueError, instead of failing with unrelated
http://hg.python.org/cpython/rev/12f3e86e9041

New changeset 55318658e1be by Senthil Kumaran in branch 'default':
default - Fix closes Issue6090 - Raise a ValueError, instead of failing with unrelated
http://hg.python.org/cpython/rev/55318658e1be
msg145927 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-10-19 17:54
Fixed in all active branches. Thanks for the patch, Petri. 
Mark, for this issue, raising ValueError from zipfile was seemingly a  right thing to do, the previous error from struct for a side effect of sending a value lower than 1980.
History
Date User Action Args
2011-10-19 17:54:46orsenthilsetnosy: + orsenthil
messages: + msg145927
2011-10-19 17:53:01python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg145925

resolution: fixed
stage: patch review -> resolved
2011-07-06 20:32:52petri.lehtinenlinkissue12198 superseder
2011-07-06 20:30:17petri.lehtinensettitle: zipfile: Bad error message when zipping a with timestamp before 1980 -> zipfile: Bad error message when zipping a file with timestamp before 1980
2011-07-06 20:29:46petri.lehtinensetfiles: + zipfile_timestamps_before_1980.patch


title: zipfile DeprecationWarning Python in 2.6, failure in 2.7 -> zipfile: Bad error message when zipping a with timestamp before 1980
keywords: + patch, needs review
nosy: + petri.lehtinen
versions: - Python 2.6
messages: + msg139950
stage: test needed -> patch review
2010-04-13 09:13:33mark.dickinsonsetnosy: + mark.dickinson
messages: + msg103024
2010-04-07 11:14:23loewissetpriority: critical -> normal
nosy: + loewis
messages: + msg102534

2010-04-06 14:32:57pitrousetpriority: normal -> critical
2010-04-06 12:33:53r.david.murraysetnosy: + r.david.murray
title: zipfile DeprecationWarning Python 2.5/2.6 -> zipfile DeprecationWarning Python in 2.6, failure in 2.7
messages: + msg102461

stage: needs patch -> test needed
2010-04-06 08:17:42ezio.melottisetversions: - Python 2.5
nosy: + ezio.melotti

priority: normal
type: behavior
stage: needs patch
2010-04-06 07:54:46techtoniksetfiles: + test6090.py


components: + Library (Lib), - Extension Modules
title: zipfile DeprecationWarning Python 2.6.2 -> zipfile DeprecationWarning Python 2.5/2.6
nosy: + techtonik
versions: + Python 2.5, Python 2.7
messages: + msg102437
2009-08-21 17:32:52cedsetnosy: + ced
2009-05-22 16:50:58ivbcreate