Skip to content

memory leak in ZipArchive->setEncryptionName() #19932

Closed

Description

@chongwick

Description

The following code:

<?php
$v_346432 = new ZipArchive();
$v_346433 = __DIR__;
$v_346434 = '/80833.zip';
$v_346435 = $v_346433 . $v_346434;
$v_346436 = ZipArchive::CREATE;
$v_346437 = $v_346432->open($v_346435,$v_346436,);
$v_346470 = __DIR__;
$v_346471 = '/80833.zip';
$v_346472 = $v_346470 . $v_346471;
$v_346439 = $v_346432->setPassword($v_346472,);
$v_346440 = 'test.txt';
$v_346441 = 'This is a test string.';
$v_346442 = $v_346432->addFromString($v_346440,$v_346441,);
$v_346443 = 'test.txt';
$v_346444 = ZipArchive::EM_AES_256;
$v_346445 = 'first_password';
$v_346446 = $v_346432->setEncryptionName($v_346443,$v_346444,$v_346445,);
$v_346447 = 'test2.txt';
$v_346448 = 'This is another test string.';
$v_346449 = $v_346432->addFromString($v_346447,$v_346448,);
$v_346477 = 'test.txt';
$v_346451 = ZipArchive::EM_AES_256;
$v_346452 = 'second_password';
$v_346453 = $v_346432->setEncryptionName($v_346477,$v_346451,$v_346452,);

Resulted in this output:

==2594328==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 15 byte(s) in 1 object(s) allocated from:
    #0 0x66e644 in strdup (/home/w023dtc/nightly_php/php-src/sapi/cli/php+0x66e644)
    #1 0x14d56e8511cf in zip_file_set_encryption (/lib/x86_64-linux-gnu/libzip.so.4+0x71cf)
    #2 0x4a56b23 in zim_ZipArchive_setEncryptionName /home/w023dtc/nightly_php/php-src/ext/zip/php_zip.c:2341:6
    #3 0x5f318fb in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER /home/w023dtc/nightly_php/php-src/Zend/zend_vm_execute.h:2152:4
    #4 0x5c7091b in execute_ex /home/w023dtc/nightly_php/php-src/Zend/zend_vm_execute.h:115722:12
    #5 0x5c72eac in zend_execute /home/w023dtc/nightly_php/php-src/Zend/zend_vm_execute.h:121434:2
    #6 0x69f5fc9 in zend_execute_script /home/w023dtc/nightly_php/php-src/Zend/zend.c:1977:3
    #7 0x51d2f5a in php_execute_script_ex /home/w023dtc/nightly_php/php-src/main/main.c:2640:13
    #8 0x51d4098 in php_execute_script /home/w023dtc/nightly_php/php-src/main/main.c:2680:9
    #9 0x6a0aeda in do_cli /home/w023dtc/nightly_php/php-src/sapi/cli/php_cli.c:951:5
    #10 0x6a052bf in main /home/w023dtc/nightly_php/php-src/sapi/cli/php_cli.c:1362:18
    #11 0x14d56e62ad8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #12 0x14d56e62ae3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #13 0x607ae4 in _start (/home/w023dtc/nightly_php/php-src/sapi/cli/php+0x607ae4)

SUMMARY: AddressSanitizer: 15 byte(s) leaked in 1 allocation(s).
ASAN_OPTIONS="fast_unwind_on_malloc=0" php script.php

PHP Version

nightly

Operating System

ubuntu 22.04

Activity

  1. devnexen commented on Sep 23, 2025

    @devnexen
    Member

    seems something like zip_file_set_encryption(intern, idx, ZIP_EM_NONE, NULL); is the way to handle the underlying password part with those two successive setEncryptionName() calls (same issue with setEncryptionIndex I assume). will have a look later.

  2. self-assigned this
    on Sep 23, 2025
  3. added a commit that references this issue on Sep 23, 2025
    db445cb
  4. added a commit that references this issue on Sep 29, 2025
    3ee56f6
  5. remicollet commented on Sep 30, 2025

    @remicollet
    Member

    Indeed there is a leak, but this one is not in PHP, but in the used library

    Reported for a proper fix in the right place as nih-at/libzip#506

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