tarfile: Degenerate TARs with global PAX headers are not handled correctly
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
It appears that tarfile.TarFile fails opening PAX TAR files if the only thing they contain is the global headers, no matter if created with the module or with the tar tool. The exception raised is tarfile.ReadError: end of file header. The tar executable handles those files perfectly.
Reproducer
import subprocess
import traceback
import tarfile
import sys
import io
#
# Non-empty Python-created files work
#
filename = "non_empty_python.tar"
with tarfile.TarFile(filename,
mode="w",
format=tarfile.PAX_FORMAT,
pax_headers=dict(abc="def")
) as t:
t.addfile(tarfile.TarInfo("ghi.txt"), io.BytesIO(b"ghi"))
subprocess.check_call(["tar", "tf", filename],
stdout=subprocess.DEVNULL)
with tarfile.TarFile(filename, mode="a"):
pass
#
# Non-empty tar-created files work
#
filename = "non_empty_tar.tar"
subprocess.check_call(["/bin/bash", "-c", f"""
tar -c -H pax --pax-option='foo=bar' -f {filename} \
-P --transform 's/.*/ghi.txt/' <(echo ghi)
"""])
subprocess.check_call(["tar", "tf", filename],
stdout=subprocess.DEVNULL)
with tarfile.TarFile(filename, mode="a"):
pass
#
# Empty Python-created files break
#
filename = "empty_python.tar"
with tarfile.TarFile(filename,
mode="w",
format=tarfile.PAX_FORMAT,
pax_headers=dict(abc="def")
) as t:
pass
subprocess.check_call(["tar", "tf", filename],
stdout=subprocess.DEVNULL)
try:
with tarfile.TarFile(filename, mode="a"):
pass
except Exception:
print(f"Opening empty Python-created PAX TAR {filename!r} failed:",
file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
#
# Empty tar-created files break
#
filename = "empty_tar.tar"
subprocess.check_call(["/bin/bash", "-c", f"""
tar -c -H pax --pax-option='foo=bar' -f {filename} \
--files-from=/dev/null
"""])
subprocess.check_call(["tar", "tf", filename],
stdout=subprocess.DEVNULL)
try:
with tarfile.TarFile(filename, mode="a"):
pass
except Exception:
print(f"Opening empty tar-created PAX TAR {filename!r} failed:",
file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-149647
- gh-156792
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với reproducer và đường dẫn mở tarfile.TarFile ở chế độ append, tập trung vào các archive chỉ chứa các global PAX header. Bổ sung kiểm thử hồi quy cho cả các archive PAX rỗng được tạo bằng Python và bằng tar, đồng thời xác minh rằng có thể mở chúng ở chế độ "a" thành công mà không gặp ReadError.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100