Skip to content

Commit 9a84866

Browse files
authored
Add files via upload
1 parent 4eba74a commit 9a84866

2 files changed

Lines changed: 64 additions & 54 deletions

File tree

pyfoxfile.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def _get(section_dict, key, default=None):
667667
__version_date__ = str(__version_date_info__[0]) + "." + str(
668668
__version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
669669
__revision__ = __version_info__[3]
670-
__revision_id__ = "$Id$"
670+
__revision_id__ = "$Id: 079d12caf8edd645d9e4505ee2a3c5f6125c79d1 $"
671671
if(__version_info__[4] is not None):
672672
__version_date_plusrc__ = __version_date__ + \
673673
"-" + str(__version_date_info__[4])
@@ -3908,30 +3908,41 @@ def gzip_decompress_bytes_all_members(blob):
39083908
return _gzip_decompress_multimember(bytes(blob))
39093909

39103910
def TarFileCheck(infile):
3911+
tar = None
3912+
pos = None
39113913
try:
3912-
if is_tarfile(infile):
3913-
return True
3914+
if hasattr(infile, "read"):
3915+
# Only do this if the file object is seekable
3916+
pos = infile.tell()
3917+
tar = tarfile.open(fileobj=infile, mode="r:")
39143918
else:
3915-
pass
3916-
except TypeError:
3917-
try:
3918-
# Check if the input is a file object
3919-
if hasattr(infile, "read"):
3920-
# Save the current file position
3921-
current_position = infile.tell()
3922-
# Attempt to open the file object as a tar file
3923-
with tarfile.open(fileobj=infile) as tar:
3924-
pass
3925-
# Restore the file position
3926-
infile.seek(current_position)
3927-
else:
3928-
# Assume it's a filename and attempt to open it as a tar file
3929-
with tarfile.open(name=infile) as tar:
3930-
pass
3931-
return True
3932-
except (tarfile.TarError, AttributeError, IOError):
3919+
tar = tarfile.open(infile, mode="r:")
3920+
3921+
member = tar.next()
3922+
if member is None:
39333923
return False
39343924

3925+
if not member.name or "\x00" in member.name:
3926+
return False
3927+
3928+
# if not member.name.isprintable():
3929+
# return False
3930+
3931+
return True
3932+
3933+
except (tarfile.TarError, AttributeError, OSError, IOError):
3934+
return False
3935+
finally:
3936+
try:
3937+
if tar is not None:
3938+
tar.close()
3939+
finally:
3940+
try:
3941+
if pos is not None and hasattr(infile, "seek"):
3942+
infile.seek(pos)
3943+
except Exception:
3944+
return False
3945+
39353946

39363947
def ZipFileCheck(infile):
39373948
try:
@@ -9328,12 +9339,6 @@ def UncompressFileAlt(fp, formatspecs=__file_format_multi_dict__, filestart=0,
93289339
else:
93299340
src = fp
93309341

9331-
# Probe at filestart using RAW handle
9332-
try:
9333-
src.seek(filestart, 0)
9334-
except Exception:
9335-
pass
9336-
93379342
kind = CheckCompressionType(src, formatspecs, filestart, False)
93389343
# Optional canonicalization so names match your compressionsupport entries
93399344
if kind == "bz2":

pyfoxfile_py3.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ def _get(section_dict, key, default=None):
705705
__version_date__ = str(__version_date_info__[0]) + "." + str(
706706
__version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2)
707707
__revision__ = __version_info__[3]
708-
__revision_id__ = "$Id$"
708+
__revision_id__ = "$Id: 6bbc1acec93c6b517faae1036b4a6897565bb414 $"
709709
if(__version_info__[4] is not None):
710710
__version_date_plusrc__ = __version_date__ + \
711711
"-" + str(__version_date_info__[4])
@@ -3178,30 +3178,41 @@ def gzip_decompress_bytes_all_members(blob):
31783178
return _gzip_decompress_multimember(bytes(blob))
31793179

31803180
def TarFileCheck(infile):
3181+
tar = None
3182+
pos = None
31813183
try:
3182-
if is_tarfile(infile):
3183-
return True
3184+
if hasattr(infile, "read"):
3185+
# Only do this if the file object is seekable
3186+
pos = infile.tell()
3187+
tar = tarfile.open(fileobj=infile, mode="r:")
31843188
else:
3185-
pass
3186-
except TypeError:
3187-
try:
3188-
# Check if the input is a file object
3189-
if hasattr(infile, "read"):
3190-
# Save the current file position
3191-
current_position = infile.tell()
3192-
# Attempt to open the file object as a tar file
3193-
with tarfile.open(fileobj=infile) as tar:
3194-
pass
3195-
# Restore the file position
3196-
infile.seek(current_position)
3197-
else:
3198-
# Assume it's a filename and attempt to open it as a tar file
3199-
with tarfile.open(name=infile) as tar:
3200-
pass
3201-
return True
3202-
except (tarfile.TarError, AttributeError, IOError):
3189+
tar = tarfile.open(infile, mode="r:")
3190+
3191+
member = tar.next()
3192+
if member is None:
32033193
return False
32043194

3195+
if not member.name or "\x00" in member.name:
3196+
return False
3197+
3198+
# if not member.name.isprintable():
3199+
# return False
3200+
3201+
return True
3202+
3203+
except (tarfile.TarError, AttributeError, OSError, IOError):
3204+
return False
3205+
finally:
3206+
try:
3207+
if tar is not None:
3208+
tar.close()
3209+
finally:
3210+
try:
3211+
if pos is not None and hasattr(infile, "seek"):
3212+
infile.seek(pos)
3213+
except Exception:
3214+
return False
3215+
32053216

32063217
def ZipFileCheck(infile):
32073218
try:
@@ -8596,12 +8607,6 @@ def UncompressFileAlt(fp, formatspecs=__file_format_multi_dict__, filestart=0,
85968607
else:
85978608
src = fp
85988609

8599-
# Probe at filestart using RAW handle
8600-
try:
8601-
src.seek(filestart, 0)
8602-
except Exception:
8603-
pass
8604-
86058610
kind = CheckCompressionType(src, formatspecs, filestart, False)
86068611
# Optional canonicalization so names match your compressionsupport entries
86078612
if kind == "bz2":

0 commit comments

Comments
 (0)