|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78641 addGlob modifies value of constant when used in remove_path with trailing slash
Submitted: 2019-10-07 15:08 UTC Modified: 2019-10-08 07:48 UTC
From: support at hiorg-server dot de Assigned: cmb (profile)
Status: Closed Package: Zip Related
PHP Version: 7.3.10 OS: Debian GNU/Linux 10 (buster)
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:
Solve the problem:
37 + 17 = ?
Subscribe to this entry?

 [2019-10-07 15:08 UTC] support at hiorg-server dot de
After adding a file by addGlob using add_path and remove_path options, the value of the constant used to define the "remove_path" has changed if it has a trailing slash.

Maybe the code block in line 1604/1605 of php-src/ext/zip/php_zip.c ( causes this bug since in these lines the "remove_path" will be modified.

Removing the trailing slash turned out to be a simple workaround for this issue.

I have used the following Dockerfile to build a docker container with php7.3.10 to reproduce this bug.

FROM php:7.3.10-cli

RUN apt-get clean
RUN apt-get update

#install some base extensions
RUN apt-get install -y \
        libzip-dev \
        zip \
  && docker-php-ext-configure zip --with-libzip \
  && docker-php-ext-install zip

Test script:

define("TMPDIR", __DIR__ . "/");

$file = 'foo-bar';

$zip = new ZipArchive();
$zip->open("", ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addGlob($file, 0, ["remove_path" => TMPDIR]);

Expected result:
string(15) "/usr/src/myapp/"
string(15) "/usr/src/myapp/"

Actual result:
string(15) "/usr/src/myapp/"
string(15) "/usr/src/myapp"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-07 17:09 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2019-10-07 17:09 UTC]
Indeed!  Thanks for reporting.
 [2019-10-08 06:35 UTC] support at hiorg-server dot de
There is one more thing we would like to add: If the constant is defined in an include script this bug can have a negative side effect for other scripts, too, if they depend on the same constant which can lead to endless debugging sessions.

We found out that the value of the constant is invalid until the include script which defines the constant will be modified (e.g. by calling "touch include.php"). This might imply that the bug changes the cached bytecode?
 [2019-10-08 07:48 UTC]
> Removing the trailing slash turned out to be a simple workaround
> for this issue.

You likely want to stick with this workaround, because bug #72374
will only be fixed as of PHP 8.0.0.

> This might imply that the bug changes the cached bytecode?

At least the attempt could be made.
 [2019-10-08 07:51 UTC]
Automatic comment on behalf of
Log: Fix #78641: addGlob can modify given remove_path value
 [2019-10-08 07:51 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 22:01:28 2024 UTC