micropython / micropython/micropython-lib

tarfile-write issue with file/folder permissions

オープン
#797 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

主要言語
Python
スター
2.9k
フォーク
1.1k
平均マージ
7日 6時間
マージ済み PR(30日)
3

説明

Context

I've been playing with tarfile for a few days and yesterday started trying to create my own archives using tarfile-write installed via mip.

Adding a folder to it works recursively, but transferring the file to the PC via mpremote and expanding it yields all files and folders with --- --- --- permissions (0x000).

Discovery

I investigated and found the source of the issue is related to how the TarInfo object is composed in these lines

in particular on line 102 we find mode to be set to the os.stat(FILE)[0]

tarinfo.mode = stat[0]

stat[0] is either 0x8000 (file) or 0x4000 (folder).
And the subsequently applied masking yields 0x000 as permissions set while adding it to the archive.
I think that mode should be safely set to 0x1a4 > 644 > rw- r-- r--

I have tested by manually composing a TarInfo object to be handed to addfile() rather than patching add()

How to reproduce:
import tarfile
import os

os.mkdir('test_folder')
f = open('test_folder/test_file_01.txt', 'w')
f.write('file 01')
f.close()

os.mkdir('test_folder/sub_folder')

f = open('test_folder/sub_folder/test_file_02.txt', 'w')
f.write('file 02')
f.close()

archive = tarfile.TarFile('test_archive.tar', 'w')
archive.add('test_folder')
archive.close()

Copy the archive from the board to the PC via mpremote cp :test_archive.tar test_archive.tar

Expand the archive and verify the permissions for test_folder.
From Mac os I was not able to chmod 644 test_folder, but using the UI I could unrestrict access.
CleanShot 2024-02-03 at 21 50 23@2x

Looking at the folder content you can verify the same permission issue happens with sub_folder and contained file(s)
CleanShot 2024-02-03 at 21 51 27@2x

Environment:
I run a custom build for ESP32-S3, but this issue is not related to changes I have applied
(name='micropython', version=(1, 23, 0, 'preview'), _machine='LilyGo T-QT Pro with ESP32S3', _mpy=10758)

MicroPython v1.23.0-preview.48.g076516d88.dirty on 2024-01-21; LilyGo T-QT Pro with ESP32S3
Board: ESP32-S3
TarFile version: '0.4.1'

Hope someone can take a look :)
u.

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

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

はじめの一歩

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

調査の方向性

python-stdlib/tarfile-write/tarfile/write.py の 102-106 行付近にある TarInfo の構成から始め、次に tarfile.TarFile.add() を使って再現を実行し、展開したアーカイブの権限を確認します。stat から導出されたモードとアーカイブに保存されたモードを比較します。展開したファイルとフォルダーが 0x000 ではなく、使用可能な権限を保持していれば完了です。

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

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

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

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