tarfile indeterminate TarInfo.size when PAX headers contain `size` and `GNU.sparse.realsize` keys at the same time
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:
Hello,
I am currently debugging this issue.
I have noticed that the bug can be reproduced when the problematic file is truncated to 9 GiB B but it does not happen when truncated to 8 GiB.
The problem seems to be that the next member offset is computed wrong. It seems to point 512 B after the correct TAR header, which, in this case, points into the data for the extended attributes such as 30 mtime=1752348[...].
One of the differences seems to be this code part, which is not hit for the working case:
While looking into the line above, i.e., into _apply_pax_info, I noticed that there is no definite order for applying the size even though it can appear multiple times!
In the non-working case, the PAX headers look like this:
{'GNU.sparse.major': '1',
'GNU.sparse.minor': '0',
'GNU.sparse.name': 'userdata',
'GNU.sparse.realsize': '9663676416',
'atime': '1752349406.975921575',
'ctime': '1752349534.57652562',
'mtime': '1752349534.57652562',
'size': '9602318848'}
I.e, the size member first gets set to GNU.sparse.realsize and then to size. The debug output looks like this:
[_apply_pax_info] SET SIZE to: 9663676416 from key: GNU.sparse.realsize
[_apply_pax_info] SET SIZE to: 9602318848 from key: size
[_apply_pax_info] SET key to: 1752349534.5765257 from key: mtime
Is it specified that the order of the PAX headers must always be this way? Else, one might just as well encounter it like this:
{'atime': '1752349406.975921575',
'ctime': '1752349534.57652562',
'mtime': '1752349534.57652562',
'size': '9602318848',
'GNU.sparse.major': '1',
'GNU.sparse.minor': '0',
'GNU.sparse.name': 'userdata',
'GNU.sparse.realsize': '9663676416'}
and either one of these orders would be a bug.
The working case does not have this ambiguity:
{'GNU.sparse.major': '1',
'GNU.sparse.minor': '0',
'GNU.sparse.name': 'userdata',
'GNU.sparse.realsize': '8589934592',
'atime': '1752349538.445543898',
'ctime': '1752351104.53673501',
'mtime': '1752351104.53673501'}
the debug output looks like this:
[_apply_pax_info] SET SIZE to: 8589934592 from key: GNU.sparse.realsize
[_apply_pax_info] SET key to: 1752351104.536735 from key: mtime
I.e., even if the is no ordering problem, there already are different semantics for the TarInfo.size member as one will contain GNU.sparse.realsize and the other will contain [PAXHeader.]size.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-136622
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 Lib/tarfile.py, đặc biệt là _apply_pax_info và phần xử lý kích thước xung quanh các dòng được tham chiếu. Tái hiện các trường hợp khác nhau 8 GiB và 9 GiB, đồng thời kiểm tra PR được liên kết gh-136622. Công việc được xem là hoàn tất khi ngữ nghĩa kích thước PAX và hành vi của TarInfo.size đã rõ ràng, không còn mơ hồ, và được bao phủ bởi một bài kiểm thử hồi quy phù hợp.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 20/100