|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68036 ZipArchive::setPassword does not set password
Submitted: 2014-09-17 12:44 UTC Modified: 2015-04-16 13:03 UTC
Avg. Score:4.8 ± 0.4
Reproduced:8 of 8 (100.0%)
Same Version:7 (87.5%)
Same OS:4 (50.0%)
From: it-solutions at schultz dot ch Assigned: cmb (profile)
Status: Not a bug Package: Zip Related
PHP Version: 5.6.0 OS: Windows Server 2012
Private report: No CVE-ID: None
 [2014-09-17 12:44 UTC] it-solutions at schultz dot ch
The new function setPassword seems not to work in my environment. The function returns TRUE, however no password is set to the archive.

This was also reported to 
for a different PHP 5.6 version on a different operating system.

Test script:
$zipFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . '';
$password = 'P455W0RD';
if (file_exists($zipFilePath)) {   unlink($zipFilePath); }
$zipArchive = new ZipArchive();
$zipArchive->open($zipFilePath, ZipArchive::CREATE);
if ($zipArchive->setPassword($password)) { echo 'OK' . PHP_EOL; }
foreach (range(1, 10) as $fileNumber) {
    $zipArchive->addFromString('file' . $fileNumber . '.txt', rand());

Expected result:
Created ZIP archive should have a password protection, and when opening it on a local machine with WinZIP, the program should ask for the password prior to open the archive.

Actual result:
When opening the archive with WinZIP, no password is required and you get all contents right away.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-18 00:49 UTC] miguelwmonteiro at gmail dot com
same problem here. just installed php 5.6 for this feature on ZipArchive and it doesn't work. how do they add the function setPassword to the public api and official stable docs and don't even test the basic functionality of it > setting a password to a zip...?!
 [2014-09-26 18:31 UTC] stanislav dot eckert at vizson dot de
It seems that this method works for extraction of password protected ZIP archives. The creation of password protected archives is not supported and will create normal non-protected archives. I made a comment here:
 [2015-02-10 13:21 UTC] chris dot moss at xdesign dot com
Pre 5.6 this method on decrypted the password. Post 5.6 this is supposed to allow the setting of a password. It clearly does not. This is a totally repeatable bug. And needs to be high priority.
 [2015-04-16 13:03 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-04-16 13:03 UTC]
According to the documentation[1] this is not a bug:

| This function only sets the password to be used to decompress the
| archive; it does not turn a non-password-protected ZipArchive
| into a password-protected ZipArchive.

Extending the current behavior has already been filed as request

[1] <>
 [2015-04-16 13:03 UTC]
-Package: zip +Package: Zip Related
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 20:03:39 2023 UTC