php / php/php-src

Symlinks are broken when extracting tar archive

Abierto
#19,879 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Extension: phar Feature Status: Verified
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.2k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comience en el punto de entrada PharData::extractTo y siga cómo se gestionan las entradas de enlaces simbólicos TAR durante la extracción. Reproduzca el caso de archivo proporcionado en PHP 8.2+ y verifique que file2 y b sean enlaces simbólicos que apuntan a file1 y a, respectivamente, en lugar de archivos regulares vacíos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
php
Área
backend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.