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.

Title: tarfile does not support timestamp older 1970-01-01
Type: Stage: resolved
Components: Versions: Python 2.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: dtibarra, hwm, iritkatriel, lars.gustaebel, loewis, socketpair
Priority: normal Keywords:

Created on 2012-05-14 23:48 by hwm, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg160674 - (view) Author: Hans Werner May (hwm) Date: 2012-05-14 23:48
Bug in tarfile:

In extractall, when a file exists in tarball with changetime older than (I don't know, in my case it was year 1956) tarfile raises an Overflow exception:

  File "/usr/lib64/python2.7/", line 2298, in utime
    os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
OverflowError: Python int too large to convert to C long

System: Mageia 1.0
Python version: 2.7.1
msg160685 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-05-15 06:21
The tar file format does nt support timestamps before 1970. From

"POSIX tar format can represent time stamps in the range 1970-01-01 00:00:00 through 2242-03-16 12:56:31 UTC." ...
"Portable archives should also avoid time stamps before 1970. These time stamps are a common POSIX extension but their time_t representations are negative. Many traditional tar implementations generate a two's complement representation for negative time stamps that assumes a signed 32-bit time_t; hence they generate archives that are not portable to hosts with differing time_t representations."

Out of curiosity: where did you get a file that was last modified in 1956?
msg160707 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2012-05-15 10:41
This issue is related to issue13158 which deals with a GNU tar specific extension to the original tar format. In that issue a negative number in the uid/gid fields caused problems. In your case the problem is a negative mtime field.

Reading these particular number fields was fixed in Python 3.2. You might be able to read the archive in question with that version. You should definitely try that.

Besides that, I was unable to reproduce the error you report. I just did some tests and could not even open my test archive, because it was not recognized as a tar file. I didn't come as far as the os.utime() call.
msg160712 - (view) Author: Hans Werner May (hwm) Date: 2012-05-15 11:17
"Out of curiosity: where did you get a file that was last modified in 1956?"

No idea, this was a jpeg file, probably downloaded from internet. Btw, on Linux you can manipulate the creation date with the touch command, so it is possible to create a tarball with a member which has creation date 1956, but it is not possible to extract it with the extractall method.
msg161548 - (view) Author: David Ibarra (dtibarra) Date: 2012-05-25 03:33
I too cannot reproduce this, tarfile seems to recognizes that it isn't a valid tar file (tested on OS X):

Davids-MacBook-Air:Workspace dibarra$ ls -l
total 8
-rw-r--r--  1 dibarra  staff     0 May 30  1956 testfile
Davids-MacBook-Air:Workspace dibarra$ tar -cvf testfile.tar testfile
a testfile

>>> t = tarfile.TarFile("testfile.tar")
Traceback (most recent call last):
tarfile.ReadError: missing or bad subsequent header
msg178962 - (view) Author: Марк Коренберг (socketpair) * Date: 2013-01-03 16:33
Yes, bug exists in python 2.7. The same problem - negative timestamp in mtime field. It prepresented in binary value as


in my case.
msg178971 - (view) Author: Марк Коренберг (socketpair) * Date: 2013-01-03 18:13
And yes, bug does not appear in python3.2
msg391952 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-04-26 17:19
Python 2 only issue.
Date User Action Args
2022-04-11 14:57:30adminsetgithub: 59015
2021-04-26 17:19:58iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg391952

resolution: out of date
stage: resolved
2013-01-03 18:13:23socketpairsetmessages: + msg178971
2013-01-03 16:33:18socketpairsetnosy: + socketpair
messages: + msg178962
2012-05-30 20:20:51vstinnersettitle: Bug in tarfile -> tarfile does not support timestamp older 1970-01-01
2012-05-25 03:33:32dtibarrasetnosy: + dtibarra
messages: + msg161548
2012-05-17 06:48:38lars.gustaebelsetassignee: lars.gustaebel
2012-05-15 11:17:09hwmsetmessages: + msg160712
2012-05-15 10:41:20lars.gustaebelsetnosy: + lars.gustaebel
messages: + msg160707
2012-05-15 06:21:40loewissetnosy: + loewis
messages: + msg160685
2012-05-14 23:48:28hwmcreate