[wp-trac] [WordPress Trac] #59467: Close ZIP archives before returning in `_unzip_file_ziparchive()`.
WordPress Trac
noreply at wordpress.org
Tue Sep 26 21:25:46 UTC 2023
#59467: Close ZIP archives before returning in `_unzip_file_ziparchive()`.
----------------------------+--------------------------
Reporter: costdev | Owner: costdev
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 6.4
Component: Filesystem API | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch | Focuses: performance
----------------------------+--------------------------
Description changed by costdev:
Old description:
> In [https://github.com/WordPress/wordpress-
> develop/blob/7cf8998e4658f22570e12f04c53817472bbc744e/src/wp-
> admin/includes/file.php#L1658C5-L1658C5 _unzip_file_ziparchive()], the
> archive is opened, but there are several returns that don't close the
> archive beforehand.
>
> From the PHP manual on `ZipArchive::close()`:
> > This method is automatically called at the end of the script.
> > [https://www.php.net/manual/en/ziparchive.close.php Reference]
>
> and from the documentation for the underlying `zip_close()` from libzip:
> > If successful, archive is freed. Otherwise archive is left unchanged
> and must still be freed.
> > [https://libzip.org/documentation/zip_close.html Reference]
>
> As this function is used during installation and upgrade processes which
> are memory-intensive, let's free the archive before each of the `return`
> statements, rather than waiting until the end of the script.
>
> Note: The `return` that gets used as a result of `true !== $zopen` does
> not need a call to `$z-close()`, as freeing the archive is
> [https://github.com/nih-at/libzip/blob/main/lib/zip_open.c#L62-L73
> handled internally] by libzip's `zip_open()`.
>
> -----
>
> - Originally introduced in [13005].
> - Follow-up to: [13005], [13006], [13015], [13221], [14346] [25779].
New description:
In [https://github.com/WordPress/wordpress-
develop/blob/7cf8998e4658f22570e12f04c53817472bbc744e/src/wp-
admin/includes/file.php#L1658C5-L1658C5 _unzip_file_ziparchive()], the
archive is opened, but there are several returns that don't close the
archive beforehand.
From the PHP manual on `ZipArchive::close()`:
> This method is automatically called at the end of the script.
> [https://www.php.net/manual/en/ziparchive.close.php Reference]
and from the documentation for the underlying `zip_close()` from libzip:
> If successful, archive is freed. Otherwise archive is left unchanged and
must still be freed.
> [https://libzip.org/documentation/zip_close.html Reference]
As this function is used during installation and upgrade processes which
are memory-intensive, let's free the archive before each of the `return`
statements, rather than waiting until the end of the script.
Note: The `return` that gets used as a result of `true !== $zopen` does
not need a call to `$z->close()`, as freeing the archive is
[https://github.com/nih-at/libzip/blob/main/lib/zip_open.c#L62-L73 handled
internally] by libzip's `zip_open()`.
-----
- Originally introduced in [13005].
- Follow-up to: [13005], [13006], [13015], [13221], [14346] [25779].
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59467#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list