tarfile: addfile() doesn't set member offsets
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
It appears that tarfile.TarFile.addfile() sets neither offset nor offset_data attributes in the TarInfo added to self.members, when it's done adding the file. Members in a reopened TAR have correct values.
Reproducer
from io import BytesIO
from tarfile import TarFile, TarInfo
with TarFile("test.tar", "w") as tar:
data = b"data"
tarinfo = TarInfo("test1.txt")
tarinfo.size = len(data)
tar.addfile(tarinfo, BytesIO(data))
tarinfo = TarInfo("test2.txt")
tarinfo.size = len(data)
tar.addfile(tarinfo, BytesIO(data))
for member in tar.getmembers():
print(member.name, member.offset, member.offset_data)
with TarFile("test.tar", "r") as tar:
for member in tar.getmembers():
print(member.name, member.offset, member.offset_data)
Expected output
test1.txt 0 512
test2.txt 1024 1536
test1.txt 0 512
test2.txt 1024 1536
Actual output
test1.txt 0 0
test2.txt 0 0
test1.txt 0 512
test2.txt 1024 1536
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-150128
- gh-150131
- gh-150278
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 tarfile.TarFile.addfile() 開始,將記憶體中的 TarInfo offset 與重新開啟封存檔時產生的值進行比較。執行提供的 BytesIO 重現程式,並確認 getmembers() 對兩個成員都回報預期的 offset 和 offset_data 值;開始前查看相關的 PR gh-150128、gh-150131 和 gh-150278。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100