php.net |  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
Votes:8
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 - 26 = ?
Subscribe to this entry?

 
 [2014-09-17 12:44 UTC] it-solutions at schultz dot ch
Description:
------------
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 
http://stackoverflow.com/questions/24190502/ziparchivesetpassword-doesnt-set-a-password-to-my-newly-created-file 
for a different PHP 5.6 version on a different operating system.

Test script:
---------------
$zipFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'filename.zip';
$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());
}
$zipArchive->close();


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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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: http://php.net/manual/en/ziparchive.setpassword.php
 [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] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-04-16 13:03 UTC] cmb@php.net
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
#67590.

[1] <http://php.net/manual/en/ziparchive.setpassword.php>
 [2015-04-16 13:03 UTC] cmb@php.net
-Package: zip +Package: Zip Related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 17:01:30 2024 UTC