[issue40757] tarfile: ignore_zeros = True won't raise exception even on invalid (non-zero) TARs

2022-01-23 Thread Irit Katriel


Irit Katriel  added the comment:

Thank you for clarifying. I can reproduce this on 3.11.

--
resolution: out of date -> 
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40757] tarfile: ignore_zeros = True won't raise exception even on invalid (non-zero) TARs

2022-01-21 Thread mxmlnkn


mxmlnkn  added the comment:

I think you misunderstood. foo.txt is a file, which actually exists but 
contains non-TAR data. E.g. try:

base64 /dev/urandom | head -c $(( 2048 ))  > foo.txt
python3 -c 'import tarfile; print(list(tarfile.open("foo.txt")))'

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.9/tarfile.py", line 1616, in open
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully

python3 -c 'import tarfile; print(list(tarfile.open("foo.txt", 
ignore_zeros=True)))'

[]

--
status: pending -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40757] tarfile: ignore_zeros = True won't raise exception even on invalid (non-zero) TARs

2022-01-21 Thread Irit Katriel


Irit Katriel  added the comment:

I am unable to reproduce this on 3.11:

>>> import tarfile

>>> tarfile.open( "foo.txt" )
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/iritkatriel/src/cpython-1/Lib/tarfile.py", line 1613, in open
return func(name, "r", fileobj, **kwargs)
   ^^
  File "/Users/iritkatriel/src/cpython-1/Lib/tarfile.py", line 1679, in gzopen
fileobj = GzipFile(name, mode + "b", compresslevel, fileobj)
  ^^
  File "/Users/iritkatriel/src/cpython-1/Lib/gzip.py", line 174, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
   ^
FileNotFoundError: [Errno 2] No such file or directory: 'foo.txt'



>>> tarfile.open( "foo.txt", ignore_zeros = True )
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/iritkatriel/src/cpython-1/Lib/tarfile.py", line 1613, in open
return func(name, "r", fileobj, **kwargs)
   ^^
  File "/Users/iritkatriel/src/cpython-1/Lib/tarfile.py", line 1679, in gzopen
fileobj = GzipFile(name, mode + "b", compresslevel, fileobj)
  ^^
  File "/Users/iritkatriel/src/cpython-1/Lib/gzip.py", line 174, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
   ^
FileNotFoundError: [Errno 2] No such file or directory: 'foo.txt'
>>>

--
nosy: +iritkatriel
resolution:  -> out of date
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40757] tarfile: ignore_zeros = True won't raise exception even on invalid (non-zero) TARs

2020-05-24 Thread mxmlnkn


New submission from mxmlnkn :

Normally, when opening an existing non-TAR file, e.g., a file with random data, 
an exception is raised:

tarfile.open( "foo.txt" )

---
ReadError Traceback (most recent call last)
 in ()
> 1 f = tarfile.open( "notes.txt", ignore_zeros = False )

/usr/lib/python3.7/tarfile.py in open(cls, name, mode, fileobj, bufsize, 
**kwargs)
   1576 fileobj.seek(saved_pos)
   1577 continue
-> 1578 raise ReadError("file could not be opened successfully")
   1579 
   1580 elif ":" in mode:

ReadError: file could not be opened successfully

However, when specifying ignore_zeros = True, this check against invalid data 
seems to be turned off. Note that it is >invalid< data not >zero< data and 
therefore should still raise an exception!

tarfile.open( "foo.txt", ignore_zeros = True )

Iterating over that opened tarfile also works without exception however nothing 
will be iterated over, i.e., it behaves like an empty TAR instead of like an 
invalid TAR.

--
components: Library (Lib)
messages: 369816
nosy: mxmlnkn
priority: normal
severity: normal
status: open
title: tarfile: ignore_zeros = True won't raise exception even on invalid 
(non-zero) TARs
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com