python / python/cpython

Align with GNU Tar when a file name is too long

オープン
#130,819 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

Recently I found tarfile may generate a file slightly different with the one made by GNU Tar (https://www.gnu.org/software/tar/), especially when a path name is longer than 100 bytes.

Here's the test code:

# py-tar.py
import tarfile, io
memory_file = io.BytesIO()
tar_obj = tarfile.open(name=None, mode="w", fileobj=memory_file, format=tarfile.GNU_FORMAT)
tar_info = tarfile.TarInfo("abcdef" * 20)
tar_info.type = tarfile.DIRTYPE
tar_info.mode = 0o755
tar_info.mtime = 1609459200  # UTC 2021-01-01
tar_info.uid = 1000
tar_info.gid = 1000
tar_info.uname = "ubuntu"
tar_info.gname = "ubuntu"
tar_obj.addfile(tar_info, None)
tar_obj.close()
memory_file.seek(0)
binary_data = memory_file.read()
# import binascii
# hex_data = binascii.hexlify(binary_data)
# sep = 16
# for i in range(0, len(hex_data), sep * 2):
#     part = hex_data[i:i + sep * 2]
#     print(*(part[i:i+2].decode() for i in range(0, len(part), 2)), binary_data[i//2:][:sep], sep=" ")
with open("py.tar", "wb") as fp:
    fp.write(binary_data)
mkdir -m 755 abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef
tar cf gnu.tar --sort=name --owner=ubuntu:1000 --group=ubuntu:1000 --mtime='UTC 2021-01-01' abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef/
python ./py-tar.py

As a result, when comparing the generated py.tar and gnu.tar, we may get such a difference:

Image

So I wonder will python might align such a detail on tarfile.GNU_FORMAT with the one of GNU tar?

BTW, here's my environment (I'm on Ubuntu 24.04), and I find the main branch of CPython has a similar Lib/tarfile.py and should have a same behavior difference:

$ LANG=C tar --version
tar (GNU tar) 1.35
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
$ LANG=C python --version
Python 3.12.3
CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs
  • gh-130820

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まずリンクされた PR gh-130820 を確認し、その後、提供された Python スクリプトと GNU Tar コマンドを使って差異を再現します。100 バイトを超える名前に対する GNU_FORMAT の処理を追跡するため、Lib/tarfile.py を調査します。このケースで生成されたアーカイブが GNU Tar と一致し、適切な箇所にリグレッションカバレッジが追加されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。