Skip to content

Commit c5c2647

Browse files
authored
Add files via upload
1 parent 36ae3b2 commit c5c2647

2 files changed

Lines changed: 64 additions & 54 deletions

File tree

pyarchivefile.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def _get(section_dict, key, default=None):
660660
__version_date__ = str(__version_date_info__[0]) + "." + str(
661661
__version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
662662
__revision__ = __version_info__[3]
663-
__revision_id__ = "$Id$"
663+
__revision_id__ = "$Id: a38d387a7c6cdade0f2e931c6223eb024fe8d586 $"
664664
if(__version_info__[4] is not None):
665665
__version_date_plusrc__ = __version_date__ + \
666666
"-" + str(__version_date_info__[4])
@@ -3901,30 +3901,41 @@ def gzip_decompress_bytes_all_members(blob):
39013901
return _gzip_decompress_multimember(bytes(blob))
39023902

39033903
def TarFileCheck(infile):
3904+
tar = None
3905+
pos = None
39043906
try:
3905-
if is_tarfile(infile):
3906-
return True
3907+
if hasattr(infile, "read"):
3908+
# Only do this if the file object is seekable
3909+
pos = infile.tell()
3910+
tar = tarfile.open(fileobj=infile, mode="r:")
39073911
else:
3908-
pass
3909-
except TypeError:
3910-
try:
3911-
# Check if the input is a file object
3912-
if hasattr(infile, "read"):
3913-
# Save the current file position
3914-
current_position = infile.tell()
3915-
# Attempt to open the file object as a tar file
3916-
with tarfile.open(fileobj=infile) as tar:
3917-
pass
3918-
# Restore the file position
3919-
infile.seek(current_position)
3920-
else:
3921-
# Assume it's a filename and attempt to open it as a tar file
3922-
with tarfile.open(name=infile) as tar:
3923-
pass
3924-
return True
3925-
except (tarfile.TarError, AttributeError, IOError):
3912+
tar = tarfile.open(infile, mode="r:")
3913+
3914+
member = tar.next()
3915+
if member is None:
39263916
return False
39273917

3918+
if not member.name or "\x00" in member.name:
3919+
return False
3920+
3921+
# if not member.name.isprintable():
3922+
# return False
3923+
3924+
return True
3925+
3926+
except (tarfile.TarError, AttributeError, OSError, IOError):
3927+
return False
3928+
finally:
3929+
try:
3930+
if tar is not None:
3931+
tar.close()
3932+
finally:
3933+
try:
3934+
if pos is not None and hasattr(infile, "seek"):
3935+
infile.seek(pos)
3936+
except Exception:
3937+
return False
3938+
39283939

39293940
def ZipFileCheck(infile):
39303941
try:
@@ -9321,12 +9332,6 @@ def UncompressFileAlt(fp, formatspecs=__file_format_multi_dict__, filestart=0,
93219332
else:
93229333
src = fp
93239334

9324-
# Probe at filestart using RAW handle
9325-
try:
9326-
src.seek(filestart, 0)
9327-
except Exception:
9328-
pass
9329-
93309335
kind = CheckCompressionType(src, formatspecs, filestart, False)
93319336
# Optional canonicalization so names match your compressionsupport entries
93329337
if kind == "bz2":

pyarchivefile_py3.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def _get(section_dict, key, default=None):
698698
__version_date__ = str(__version_date_info__[0]) + "." + str(
699699
__version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
700700
__revision__ = __version_info__[3]
701-
__revision_id__ = "$Id$"
701+
__revision_id__ = "$Id: f00d2424f6164d172a72f02bf2ebbc95ef590f0b $"
702702
if(__version_info__[4] is not None):
703703
__version_date_plusrc__ = __version_date__ + \
704704
"-" + str(__version_date_info__[4])
@@ -3171,30 +3171,41 @@ def gzip_decompress_bytes_all_members(blob):
31713171
return _gzip_decompress_multimember(bytes(blob))
31723172

31733173
def TarFileCheck(infile):
3174+
tar = None
3175+
pos = None
31743176
try:
3175-
if is_tarfile(infile):
3176-
return True
3177+
if hasattr(infile, "read"):
3178+
# Only do this if the file object is seekable
3179+
pos = infile.tell()
3180+
tar = tarfile.open(fileobj=infile, mode="r:")
31773181
else:
3178-
pass
3179-
except TypeError:
3180-
try:
3181-
# Check if the input is a file object
3182-
if hasattr(infile, "read"):
3183-
# Save the current file position
3184-
current_position = infile.tell()
3185-
# Attempt to open the file object as a tar file
3186-
with tarfile.open(fileobj=infile) as tar:
3187-
pass
3188-
# Restore the file position
3189-
infile.seek(current_position)
3190-
else:
3191-
# Assume it's a filename and attempt to open it as a tar file
3192-
with tarfile.open(name=infile) as tar:
3193-
pass
3194-
return True
3195-
except (tarfile.TarError, AttributeError, IOError):
3182+
tar = tarfile.open(infile, mode="r:")
3183+
3184+
member = tar.next()
3185+
if member is None:
31963186
return False
31973187

3188+
if not member.name or "\x00" in member.name:
3189+
return False
3190+
3191+
# if not member.name.isprintable():
3192+
# return False
3193+
3194+
return True
3195+
3196+
except (tarfile.TarError, AttributeError, OSError, IOError):
3197+
return False
3198+
finally:
3199+
try:
3200+
if tar is not None:
3201+
tar.close()
3202+
finally:
3203+
try:
3204+
if pos is not None and hasattr(infile, "seek"):
3205+
infile.seek(pos)
3206+
except Exception:
3207+
return False
3208+
31983209

31993210
def ZipFileCheck(infile):
32003211
try:
@@ -8589,12 +8600,6 @@ def UncompressFileAlt(fp, formatspecs=__file_format_multi_dict__, filestart=0,
85898600
else:
85908601
src = fp
85918602

8592-
# Probe at filestart using RAW handle
8593-
try:
8594-
src.seek(filestart, 0)
8595-
except Exception:
8596-
pass
8597-
85988603
kind = CheckCompressionType(src, formatspecs, filestart, False)
85998604
# Optional canonicalization so names match your compressionsupport entries
86008605
if kind == "bz2":

0 commit comments

Comments
 (0)