Skip to content

Commit 517e8ad

Browse files
committed
Add test for fix-phar-stream-double-free
1 parent 6060b5e commit 517e8ad

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

‎ext/phar/tests/gh18953.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Phar: Stream double free
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
--ENV--
8+
USE_ZEND_ALLOC=0
9+
--FILE--
10+
<?php
11+
12+
declare(strict_types=1);
13+
14+
require __DIR__ . '/gh18953/autoload.inc';
15+
16+
// cleaning
17+
@unlink("bug.phar");
18+
@unlink("bug.phar.gz");
19+
20+
// create a phar
21+
$phar = new Phar("bug.phar");
22+
$phar->startBuffering();
23+
// add any dir
24+
$phar->addEmptyDir("dir");
25+
$phar->stopBuffering();
26+
// compress
27+
$phar->compress(Phar::GZ);
28+
29+
// this increases the chance of reproducing the problem
30+
// even with this, it's not always reproducible
31+
$obj1 = new NS1\Class1();
32+
$obj2 = new NS1\Class1();
33+
$obj2 = new NS1\Class1();
34+
$obj2 = new NS1\Class1();
35+
$obj2 = new NS1\Class1();
36+
37+
echo "Done" . PHP_EOL;
38+
?>
39+
--EXPECT--
40+
Done

‎ext/phar/tests/gh18953/autoload.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
spl_autoload_register(function ($class) {
4+
$base_dir = __DIR__ . '/src/';
5+
6+
$file = $base_dir . str_replace('\\', '/', $class) . '.inc';
7+
if (file_exists($file)) {
8+
require $file;
9+
}
10+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NS1;
6+
7+
use NS2\Interface1;
8+
9+
class Class1 implements Interface1
10+
{
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NS2;
6+
7+
interface Interface1
8+
{
9+
}

0 commit comments

Comments
 (0)