File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -2484,7 +2484,9 @@ def is_tarfile(name):
2484
2484
"""
2485
2485
try :
2486
2486
if hasattr (name , "read" ):
2487
+ pos = name .tell ()
2487
2488
t = open (fileobj = name )
2489
+ name .seek (pos )
2488
2490
else :
2489
2491
t = open (name )
2490
2492
t .close ()
Original file line number Diff line number Diff line change @@ -352,6 +352,18 @@ def test_is_tarfile_valid(self):
352
352
with open (self .tarname , "rb" ) as fobj :
353
353
self .assertTrue (tarfile .is_tarfile (io .BytesIO (fobj .read ())))
354
354
355
+ def test_is_tarfile_keeps_position (self ):
356
+ # Test for issue44289: tarfile.is_tarfile() modifies
357
+ # file object's current position
358
+ with open (self .tarname , "rb" ) as fobj :
359
+ tarfile .is_tarfile (fobj )
360
+ self .assertEqual (fobj .tell (), 0 )
361
+
362
+ with open (self .tarname , "rb" ) as fobj :
363
+ file_like = io .BytesIO (fobj .read ())
364
+ tarfile .is_tarfile (file_like )
365
+ self .assertEqual (file_like .tell (), 0 )
366
+
355
367
def test_empty_tarfile (self ):
356
368
# Test for issue6123: Allow opening empty archives.
357
369
# This test checks if tarfile.open() is able to open an empty tar
You can’t perform that action at this time.
0 commit comments