Skip to content

Fix stream double free in phar #19035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for fix-phar-stream-double-free
  • Loading branch information
dixyes authored and nielsdos committed Jul 4, 2025
commit d29a5400b41a5acf01267a613b33aee6d343c6ee
45 changes: 45 additions & 0 deletions ext/phar/tests/gh18953.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
Phar: Stream double free
--EXTENSIONS--
phar
--INI--
phar.readonly=0
--ENV--
USE_ZEND_ALLOC=0
--FILE--
<?php

declare(strict_types=1);

require __DIR__ . '/gh18953/autoload.inc';

// cleaning
@unlink("gh18953.phar");
@unlink("gh18953.phar.gz");

// create a phar
$phar = new Phar("gh18953.phar");
$phar->startBuffering();
// add any dir
$phar->addEmptyDir("dir");
$phar->stopBuffering();
// compress
$phar->compress(Phar::GZ);

// this increases the chance of reproducing the problem
// even with this, it's not always reproducible
$obj1 = new NS1\Class1();
$obj2 = new NS1\Class1();
$obj2 = new NS1\Class1();
$obj2 = new NS1\Class1();
$obj2 = new NS1\Class1();

echo "Done" . PHP_EOL;
?>
--CLEAN--
<?php
@unlink("gh18953.phar");
@unlink("gh18953.phar.gz");
?>
--EXPECT--
Done
10 changes: 10 additions & 0 deletions ext/phar/tests/gh18953/autoload.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

spl_autoload_register(function ($class) {
$base_dir = __DIR__ . '/src/';

$file = $base_dir . str_replace('\\', '/', $class) . '.inc';
if (file_exists($file)) {
require $file;
}
});
11 changes: 11 additions & 0 deletions ext/phar/tests/gh18953/src/NS1/Class1.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace NS1;

use NS2\Interface1;

class Class1 implements Interface1
{
}
9 changes: 9 additions & 0 deletions ext/phar/tests/gh18953/src/NS2/Interface1.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace NS2;

interface Interface1
{
}