php / php/php-src

Symlinks are broken when extracting tar archive

未关闭
#19,879 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Extension: phar Feature Status: Verified
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 PharData::extractTo 入口点开始,跟踪 TAR 符号链接条目在提取过程中的处理方式。在 PHP 8.2+ 上复现所提供的归档案例,并验证 file2 和 b 是分别指向 file1 和 a 的符号链接,而不是空的普通文件。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。