Symlinks are broken when extracting tar archive
Personne n'a encore pris cette issue.
- Langage dominant
- C
- Étoiles
- 40.4k
- Forks
- 8.1k
- Merge moyen
- 2 j 13 h
- PR mergées (30 j)
- 96
Description
Description
I have a TAR archive that contains symlink(s).
mkdir test
cd test
echo "file1" > file1
ln -s file1 file2
mkdir a
cd a
echo "file3" > file3
cd ..
ln -s a b
cd ..
tar -cf test.tar test
Extracting using tar works fine:
rm -r test
tar -xvf test.tar
ls -lah test
total 24K
drwxr-xr-x 3 michal michal 4.0K Sep 19 09:36 .
drwxr-xr-x 104 michal users 12K Sep 19 09:37 ..
drwxr-xr-x 2 michal michal 4.0K Sep 19 09:36 a
lrwxrwxrwx 1 michal michal 1 Sep 19 09:36 b -> a
-rw-r--r-- 1 michal michal 6 Sep 19 09:36 file1
lrwxrwxrwx 1 michal michal 5 Sep 19 09:36 file2 -> file1
The following code extracts the archive using php:
<?php
$tar = '/home/michal/test.tar';
$targetDir = '/tmp/phpissue';
$phar = new \PharData($tar);
$phar->extractTo($targetDir, null, true);
Resulted in this:
ls -lah /tmp/phpissue/test/
total 16K
drwxr-xr-x 3 michal michal 4.0K Sep 19 09:42 .
drwxr-xr-x 3 michal michal 4.0K Sep 19 09:42 ..
drwxr-xr-x 2 michal michal 4.0K Sep 19 09:42 a
-rwxrwxrwx 1 michal michal 0 Sep 19 09:42 b
-rw-r--r-- 1 michal michal 6 Sep 19 09:42 file1
-rwxrwxrwx 1 michal michal 0 Sep 19 09:42 file2
The directory "b" is just an empty file, also the file2 is just en empty file. Both were symlinks.
I expect that those symlinks are correctly extracted.
PHP Version
Tested on php8.2+ (all with the same result):
PHP 8.4.12 (cli) (built: Sep 7 2025 14:06:59) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.12, Copyright (c) Zend Technologies
with Zend OPcache v8.4.12, Copyright (c), by Zend Technologies
PHP 8.3.25 (cli) (built: Sep 7 2025 14:03:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.25, Copyright (c) Zend Technologies
with Zend OPcache v8.3.25, Copyright (c), by Zend Technologies
PHP 8.2.29 (cli) (built: Sep 7 2025 14:06:52) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.29, Copyright (c) Zend Technologies
with Zend OPcache v8.2.29, Copyright (c), by Zend Technologies
Operating System
Debian Bookworm
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez au point d’entrée PharData::extractTo et suivez la manière dont les entrées de liens symboliques TAR sont traitées lors de l’extraction. Reproduisez le cas d’archive fourni avec PHP 8.2+ et vérifiez que file2 et b sont des liens symboliques ciblant respectivement file1 et a, plutôt que des fichiers ordinaires vides.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- php
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 35/100