[issue29760] tarfile chokes on reading .tar file with no entries (but does fine if the same file is bzip2'ed)

Matt Bogosian report at bugs.python.org
Fri Mar 10 15:31:03 EST 2017


Matt Bogosian added the comment:

This patch (also attached) seems to address this particular use case:

```
--- a/Lib/tarfile.py	2016-12-17 12:41:21.000000000 -0800
+++ b/Lib/tarfile.py	2017-03-10 12:23:34.000000000 -0800
@@ -2347,7 +2347,7 @@
 
         # Advance the file pointer.
         if self.offset != self.fileobj.tell():
-            self.fileobj.seek(self.offset - 1)
+            self.fileobj.seek(max(self.offset - 1, 0))
             if not self.fileobj.read(1):
                 raise ReadError("unexpected end of data")
 
```

However, I am unfamiliar with the code, especially in light of #24259, and haven't tested it thoroughly. Oversight is needed.

----------
keywords: +patch
Added file: http://bugs.python.org/file46717/tarfile.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29760>
_______________________________________


More information about the Python-bugs-list mailing list