]> granicus.if.org Git - php/commitdiff
Fix #79315 ZipArchive::addFile doesn't honor start/length parameters
authorRemi Collet <remi@php.net>
Fri, 28 Feb 2020 09:21:19 +0000 (10:21 +0100)
committerRemi Collet <remi@php.net>
Fri, 28 Feb 2020 09:21:19 +0000 (10:21 +0100)
NEWS
ext/zip/php_zip.c
ext/zip/tests/oo_addfile.phpt

diff --git a/NEWS b/NEWS
index a6c9cbf2b572d96ebebf733f85228c26376127d8..0818f715c5d0a2f1d8c5d161a1142ee4079b7ce0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,10 @@ PHP                                                                        NEWS
 - Standard:
   . Fixed bug #79254 (getenv() w/o arguments not showing changes). (cmb)
 
+- Zip:
+  . Fixed bug #79315 (ZipArchive::addFile doesn't honor start/length
+    parameters). (Remi)
+
 20 Feb 2020, PHP 7.3.15
 
 - Core:
index e607f0f0771c399c7ff9f1c98bfb0dd352df3060..f65f70621e84f52308e9b872583420cf45ec0658 100644 (file)
@@ -1824,7 +1824,8 @@ static ZIPARCHIVE_METHOD(addFile)
                entry_name_len = ZSTR_LEN(filename);
        }
 
-       if (php_zip_add_file(intern, ZSTR_VAL(filename), ZSTR_LEN(filename), entry_name, entry_name_len, 0, 0) < 0) {
+       if (php_zip_add_file(intern, ZSTR_VAL(filename), ZSTR_LEN(filename),
+                       entry_name, entry_name_len, offset_start, offset_len) < 0) {
                RETURN_FALSE;
        } else {
                RETURN_TRUE;
index b41e3dbf2c16ccfd0be939d377da929285dc7ba9..37320de6277d36ebbf9df5cd431475dcd4a5946e 100644 (file)
@@ -20,12 +20,20 @@ if (!$zip->open($file)) {
 if (!$zip->addFile($dirname . 'utils.inc', 'test.php')) {
        echo "failed\n";
 }
+if (!$zip->addFile($dirname . 'utils.inc', 'mini.txt', 12, 34)) {
+       echo "failed\n";
+}
 if ($zip->status == ZIPARCHIVE::ER_OK) {
        dump_entries_name($zip);
        $zip->close();
 } else {
        echo "failed\n";
 }
+if (!$zip->open($file)) {
+       exit('failed');
+}
+var_dump(strlen($zip->getFromName('test.php')) == filesize($dirname . 'utils.inc'));
+var_dump(strlen($zip->getFromName('mini.txt')) == 34);
 @unlink($file);
 ?>
 --EXPECT--
@@ -34,3 +42,6 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
 2 foobar/baz
 3 entry1.txt
 4 test.php
+5 mini.txt
+bool(true)
+bool(true)