php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73119 Wrong return for ZipArchive::addEmptyDir Method
Submitted: 2016-09-20 05:58 UTC Modified: 2020-02-03 08:49 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: hoangtuan180991 at gmail dot com Assigned:
Status: Closed Package: Zip Related
PHP Version: 5.6 OS: Ubuntu 12.04
Private report: No CVE-ID: None
 [2016-09-20 05:58 UTC] hoangtuan180991 at gmail dot com
Description:
------------
function static ZIPARCHIVE_METHOD(addEmptyDir) still return true but the directory did not created.

	idx = zip_stat(intern, s, 0, &sb);
	if (idx >= 0) {
		RETVAL_FALSE;
	} else {
		if (zip_add_dir(intern, (const char *)s) == -1) {
			RETVAL_FALSE;
		}
		zip_error_clear(intern);
		RETVAL_TRUE;
	}


I propose the following patch:
`````
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -1603,10 +1603,14 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
                RETVAL_FALSE;
        } else {
                if (zip_add_dir(intern, (const char *)s) == -1) {
+                       zip_error_clear(intern);
                        RETVAL_FALSE;
                }
-              zip_error_clear(intern);
-               RETVAL_TRUE;
+               else
+               {
+                       zip_error_clear(intern);
+                       RETVAL_TRUE;
+               }
        }
 
        if (s != dirname) {

Test script:
---------------
<?php
	ini_set('memory_limit', -1);
	$archive = new ZipArchive();
	$archive->open('_test.zip', ZIPARCHIVE::CREATE);
	var_dump($archive->addEmptyDir(str_repeat("t", 0x7fffffff)));
	print_r($archive);
	$archive->close();

?>

Expected result:
----------------
bool(false)
ZipArchive Object
(
    [status] => 0
    [statusSys] => 0
    [numFiles] => 0
    [filename] => /home/tuannh/BUGS/TBB_TEST/_test.zip
    [comment] => 
)

Actual result:
--------------
bool(true)
ZipArchive Object
(
    [status] => 0
    [statusSys] => 0
    [numFiles] => 0
    [filename] => /home/tuannh/BUGS/TBB_TEST/_test.zip
    [comment] => 
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-21 02:28 UTC] stas@php.net
-Type: Security +Type: Bug
 [2016-11-13 07:28 UTC] krakjoe@php.net
-PHP Version: 7.1.0RC2 +PHP Version: 5.6
 [2016-11-13 07:28 UTC] krakjoe@php.net
Changed version, this applies to all active branches.
 [2018-03-17 18:11 UTC] cmb@php.net
-Package: Filesystem function related +Package: Zip Related
 [2020-02-03 08:49 UTC] remi@php.net
-Summary: Wrong return with addEmptyDir Zip Method +Summary: Wrong return for ZipArchive::addEmptyDir Method
 [2020-02-03 09:09 UTC] remi@php.net
Automatic comment on behalf of remi@remirepo.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0bc19a4b819fb2e43812eece8514682136af37b2
Log: Fixed bug #73119 Wrong return for ZipArchive::addEmptyDir Method
 [2020-02-03 09:09 UTC] remi@php.net
-Status: Open +Status: Closed
 [2020-02-03 09:10 UTC] remi@php.net
Automatic comment on behalf of remi@remirepo.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c274613dc76007f5227aa162e02d5943b683d37
Log: Fixed bug #73119 Wrong return for ZipArchive::addEmptyDir Method
 [2020-02-03 09:25 UTC] remi@php.net
Automatic comment on behalf of remi@remirepo.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c274613dc76007f5227aa162e02d5943b683d37
Log: Fixed bug #73119 Wrong return for ZipArchive::addEmptyDir Method
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC