This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ZipFile.write fails with bad modification time
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Linsey Alvarez, alanmcintyre, barry, brian.curtin, gradha, r.david.murray, serhiy.storchaka, xtreak
Priority: normal Keywords: patch

Created on 2007-07-25 14:54 by gradha, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
debug_session.txt gradha, 2007-07-25 14:54 Debug session showing negative mtime
ignore_negative_modification_time.txt gradha, 2007-07-25 14:56 Most likely incorrect fix to avoid this problem
Messages (6)
msg52944 - (view) Author: Grzegorz Adam Hankiewicz (gradha) Date: 2007-07-25 14:54
Running on Windows XP against a networked file server with Windows 2003 I have a file which due to some obscure reason it has a negative modification time as returned by Python os functions. When I look at the file in the explorer the modification time column is blank, and when I view the properties of the file there the modification time is set to the 25th of April of 1906 at 2:03:44.

If I try to zip this file the zip creation fails with a Value error when the file's st_mtime value is passed to time.localtime().

I'm attaching a debug session log along with a possible patch to avoid such problems, though maybe the function that returns st_mtime should never return negative values because other library functions expect zero or positive values too.

In the log you will see that it is a custom rastertech\zipfile.py file that is failing. This is just the SVN development version of zipfile along with some modifications since changes like 1739648 seem to be very low priority. The patch is generated against a clean SVN version.
msg52945 - (view) Author: Grzegorz Adam Hankiewicz (gradha) Date: 2007-07-25 14:56
File Added: ignore_negative_modification_time.txt
msg55307 - (view) Author: Grzegorz Adam Hankiewicz (gradha) Date: 2007-08-26 09:31
Any progress report on this issue, please?
msg58978 - (view) Author: Alan McIntyre (alanmcintyre) * (Python committer) Date: 2007-12-23 21:26
At the moment I don't have a Windows machine available, but on my Mac,
time.localtime doesn't seem to mind interpreting negative input values.
 So I doubt that forcing timestamps to be non-negative is the way to fix
this. 

I poked around a bit in the current 2.6 source, and it seems to me that
in this case the Windows XP localtime function doesn't like a timestamp
value that was generated by the same platform's stat function.  It seems
like raising a ValueError is the correct thing for the time module to
do, since it relies on the platform to do the conversions; what should
zipfile.writestr do?  I don't like the idea of silently using some dummy
timestamp if the conversion of os.stat results fails, and I can't think
of an alternative at the moment.
msg159533 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-04-28 19:44
An alternative is to use the current time, as for stdin.
msg348574 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-07-28 06:48
Linsey Alvarez, I am not sure how it's related to email. So I am removing the email tag and changing the subject back.
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45243
2021-10-20 12:53:55christian.heimessetversions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.6, Python 3.1, Python 2.7, Python 3.2
2019-07-28 06:48:51xtreaksettitle: Loveubylulu@gmail.com -> ZipFile.write fails with bad modification time
nosy: + xtreak

messages: + msg348574

components: - email
2019-07-28 06:26:51Linsey Alvarezsetnosy: + r.david.murray, barry, Linsey Alvarez
components: + email
2019-07-28 06:24:33Linsey Alvarezsettitle: ZipFile.write fails with bad modification time -> Loveubylulu@gmail.com
2012-04-28 19:44:56serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg159533
2010-01-17 19:04:45brian.curtinsetnosy: + brian.curtin
versions: + Python 2.6, Python 3.1, Python 2.7, Python 3.2

type: behavior
stage: test needed
2007-12-23 21:26:56alanmcintyresetnosy: + alanmcintyre
messages: + msg58978
2007-08-26 09:31:58gradhasetmessages: + msg55307
2007-07-25 14:54:52gradhacreate