Python 3.12+tarfileexception
tarfile.AbsoluteLinkError
exceptions
The 'data' filter exception for a symbolic link in the archive that points to an absolute path.
Syntax
except tarfile.AbsoluteLinkError:
A link 'conf' → '/etc/passwd' writes nothing by itself, but a later member named 'conf' writes its data through it straight into the system file. The 'tar' filter lets such a link through; only 'data' refuses it. The refusal applies even on systems without symbolic link support.
Examples
import tarfile
link = tarfile.TarInfo('conf')
link.type = tarfile.SYMTYPE
link.linkname = '/etc/passwd'
try:
tarfile.data_filter(link, 'out')
except tarfile.AbsoluteLinkError as e:
print(e) # → 'conf' is a link to an absolute path
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy