[php-src] Issue #23477: phar memory leak
| From: | LamentXU123 | Date: | Thu, 27 Aug 2026 08:15:06 +0000 |
| Subject: | [php-src] Issue #23477: phar memory leak | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252675@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/23477
Author: LamentXU123
### Description
The following code:
```php
<?php
$stub = "<?php __HALT_COMPILER(); ?>\r\n";
function u32($v) { return pack('V', $v); }
function ent($name, $data, $meta = '') {
$h = u32(strlen($name)) . $name
. u32(strlen($data)) . u32(0) . u32(strlen($data))
. u32(crc32($data)) . u32(0)
. u32(strlen($meta)) . $meta;
return [$h, $data];
}
$e1 = ent('a.txt', 'hello', 'i:1;');
$e2 = ent('a.txt', 'world', 'i:2;');
$ents = $e1[0] . $e2[0];
$contents = $e1[1] . $e2[1];
$manifest = u32(2) . "\x11\x00" . u32(0) . u32(0) . u32(0) . $ents;
file_put_contents(__DIR__ . '/dup.phar', $stub . u32(strlen($manifest)) . $manifest .
$contents);
$p = new Phar(__DIR__ . '/dup.phar');
echo iterator_count($p), PHP_EOL;
```
Resulted in this output:
```
==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 32 byte(s) in 1 object(s) allocated from:
#4 zend_string_init Zend/zend_string.h:212
#5 phar_parse_metadata_lazy ext/phar/phar.c:705
#6 phar_parse_pharfile ext/phar/phar.c:1191
#10 zim_Phar___construct ext/phar/phar_object.c:1125
Direct leak of 32 byte(s) in 1 object(s) allocated from:
#4 zend_string_init Zend/zend_string.h:212
#5 phar_parse_pharfile ext/phar/phar.c:1177
#9 zim_Phar___construct ext/phar/phar_object.c:1125
```
### PHP Version
```plain
PHP 8.6.0-dev
```
### Operating System
/