Skip to content

phar memory leak #23477

Closed
Closed

Description

@LamentXU123

Description

Originally posted by @devnexen in #23418

The following code:

<?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

PHP 8.6.0-dev

Operating System

/

Activity

  1. self-assigned this
    on Aug 27, 2026
  2. added a commit that references this issue on Aug 27, 2026
    a1b68af
  3. added a commit that references this issue on Aug 27, 2026
    cd99c6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions