1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

502 Commits

Author SHA1 Message Date
Alexandre Daubois
a8543dfdd2 Convert remaining zend_parse_parameters_none() to ZPP (#21343) 2026-03-16 09:28:08 +01:00
Arshid
45157d24ea ext/zip: Remove unreachable break after RETURN_STRING (#21458) 2026-03-16 07:37:43 +00:00
Tim Starling
605c0756c9 ext/zip: add ZipArchive::openString() method
Fixes to GH-14078:

* Rename ZipArchive::openBuffer() to ::openString().
* For consistency with ::open(), return int|bool, don't throw an
  exception on error. Provide error information via existing properties
  and accessors.
* Fix memory leak when ::openString() is called but ::close() is not
  called. Add test.
* Fix memory leak when a call to ::open() is followed by a call to
  ::openString(). Add test.
* Let libzip own the source, don't call zip_source_keep().
* Share buffer handling with ZipArchive::addFromString().

Elsewhere:

* If there is an error from zip_close() during a call to
  ZipArchive::open(), emit a warning but proceed to open the archive,
  don't return early. Add test.
* When buffers are saved by ZipArchive::addFromString(), release them
  in ZipArchive::close() and ::open(), don't accumulate buffers until
  the free_obj handler is called.
* Factor out buffer handling and reuse it in ZipArchive::openString()

Closes GH-21205.
Closes GH-14078.

Co-authored-by: Soner Sayakci <s.sayakci@shopware.com>
Co-authored-by: Ghaith Olabi <24876890+Gaitholabi@users.noreply.github.com>
2026-03-14 15:03:36 +01:00
Tim Starling
e7f022b3fc Remove ifdef guards for ZIP_RDONLY (#21195)
ZIP_RDONLY was introduced in libzip 1.0.0 which is required since
a979e9f897
2026-02-15 14:10:00 -08:00
Niels Dossche
9762c446f0 Merge branch 'PHP-8.5'
* PHP-8.5:
  zip: Don't truncate return value of zip_fread() with user sizes
2025-11-18 20:32:15 +01:00
Niels Dossche
a21783c73c Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  zip: Don't truncate return value of zip_fread() with user sizes
2025-11-18 20:31:31 +01:00
Niels Dossche
4eacb6de83 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  zip: Don't truncate return value of zip_fread() with user sizes
2025-11-18 20:31:15 +01:00
Niels Dossche
2f05830a5f zip: Don't truncate return value of zip_fread() with user sizes
The return type has been zip_int64_t since 2009, so we shouldn't
truncate to an int because the user may have requested a size that won't
fit in an int.

Closes GH-20509.
2025-11-18 20:30:42 +01:00
Niels Dossche
3977650820 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix crash in property existence test in ext/zip
2025-11-16 21:30:39 +01:00
Niels Dossche
75cd8fbb55 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix crash in property existence test in ext/zip
2025-11-16 21:29:16 +01:00
Niels Dossche
9db074d2ad Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix crash in property existence test in ext/zip
2025-11-16 21:28:57 +01:00
Niels Dossche
46a15ed439 Fix crash in property existence test in ext/zip
When type == 2, the zval is not initialized, so zval_ptr_dtor() on it
will crash.
Unfortunately couldn't test with property_exists() or Reflection because
they have fast paths that go through the property info, but fortunately
there are paths that don't implement a fast path (e.g. because it
doesn't make sense at that point), like with array_column().
So we use array_column() to trigger the crash.

Closes GH-20496.
2025-11-16 21:28:30 +01:00
David CARLIER
ac7fddfacc ext/zip: further micro optimisations. (#20362)
- earlier return on invalid inputs from some ZipArchive methods.
- apply comp_flags type check for setCompressionName()/setCompressionIndex().
and throw exception for these
- add comp_flags check when passed as userland array option.
- adding a wrapper for zip_file_set_encryption workaround.
2025-11-16 14:35:37 +00:00
Niels Dossche
5bed2a8920 Avoid string copy in ZipArchive::addFromString() (#20497)
Instead of copying the data we increment the refcount of the string.
2025-11-16 14:57:00 +01:00
David Carlier
7a93d2ca6a Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/zip: fix memory leak when encryption is passed as userland array option.
2025-11-02 21:17:19 +00:00
David Carlier
0e9c39deb9 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/zip: fix memory leak when encryption is passed as userland array option.
2025-11-02 21:17:05 +00:00
David Carlier
6d12688c9e Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  ext/zip: fix memory leak when encryption is passed as userland array option.
2025-11-02 21:16:55 +00:00
David Carlier
55f7303d73 ext/zip: fix memory leak when encryption is passed as userland array option.
Similar issue fixed in GH-19936.

close GH-20363
2025-11-02 21:15:07 +00:00
Peter Kokot
8d1a42fd10 ext/zip: Sync remaining parts for libzip >= 1.0.0 (#20365)
Follow up of GH-20355
2025-11-02 20:45:04 +01:00
David Carlier
a979e9f897 ext/zip: lifting libzip minimum support.
0.11 dates back from 2013 whereas 1.0.0 is from 2015.
Thus, simplifying the extension removing unlikely old api code usage.
centos 7 can always uses an alternative repository (e.g. remi's);
solaris 10 can access the 1.5.2 release via OpenCSW.

close GH-20355
2025-11-01 23:37:54 +00:00
David Carlier
6c1402031d ext/zip: code refactoring.
- change few helpers signatures.
- ZipArchive::extractTo now accepts only string entries for the files
  list.

close GH-20218
2025-10-27 21:19:52 +00:00
David Carlier
bac62bf31a Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/zip: ZipArchive callback missing zend_release_fcall_info_cache
2025-10-25 21:51:38 +01:00
David Carlier
3884438fe3 ext/zip: ZipArchive callback missing zend_release_fcall_info_cache
during FCC conversion (79b9fe3) in the rare cases where the lib
fails to allocate the memory for these callbacks, we return false
directly.

close GH-20293
2025-10-25 21:50:43 +01:00
Ilija Tovilo
e2da92b15c Fix ZipArchive callback being called after executor has shut down
free_obj() for objects referenced in the main symbol table may be called only
once the executor has already shut down. php_zip_cancel_callback() may attempt
to invoke a user callback, which will terminate the process because user code is
not expected to be executed at this point. We solve this by calling the callback
in dtor_obj(), which is called earlier in the shutdown sequence.

dtor_obj() will actually attempt to call it again if the object was
reinitialized in the destructor, so we also avoid calling the callback when the
executor has shut down in the first place. This should never matter in practice.

Closes GH-19602
2025-10-14 23:17:33 +02:00
David Carlier
590785ed21 Merge branch 'PHP-8.5' 2025-09-29 22:12:01 +01:00
David Carlier
2c4f4e0ee6 Merge branch 'PHP-8.4' into PHP-8.5 2025-09-29 22:11:49 +01:00
David Carlier
4e00b14029 Merge branch 'PHP-8.3' into PHP-8.4 2025-09-29 22:10:46 +01:00
David Carlier
3ee56f68ed Fix GH-19932: Zip::setEncryptionName()/setEncryptionIndex() memory leak.
On successive usage, the password is copied as much but the older
address is never freed. Thus, we are hinting a password reset to address
it.

close GH-19936
2025-09-29 22:10:17 +01:00
Tim Düsterhus
eddb0f5e8a zip: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Niels Dossche
2d545dd1b7 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-19688: Remove pattern overflow in zip addGlob()
2025-09-10 23:48:22 +02:00
Niels Dossche
98aba6c165 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-19688: Remove pattern overflow in zip addGlob()
2025-09-10 23:48:16 +02:00
Niels Dossche
901f71e6e3 Fix GH-19688: Remove pattern overflow in zip addGlob()
memcmp() can overread the filename if the filename is shorter than the
pattern.

Closes GH-19689.
2025-09-10 23:47:52 +02:00
Niels Dossche
8cd085a179 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix memory leak in zip when encountering empty glob result
2025-09-05 18:57:31 +02:00
Niels Dossche
1b49d0eb58 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak in zip when encountering empty glob result
2025-09-05 18:57:26 +02:00
Niels Dossche
216e87ad7e Fix memory leak in zip when encountering empty glob result
The case of returning 0 is inconsistent in when it returns an empty
array, furthermore the caller already returns an empty array.
Because the caller overwrites the return value in these cases, it can
cause a memory leak.

This is easier to trigger on master in some cases as different code paths
are taken with the new bundled glob. On some platforms it is also
triggerable on 8.3.

Closes GH-19715.
2025-09-05 18:56:27 +02:00
Niels Dossche
51149b65ad Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18990, bug #81029, bug #47314: SOAP HTTP socket not closing on object destruction
  Fix leak when path is too long in ZipArchive::extractTo()
  curl: Remove incorrect string release on error
2025-07-02 18:47:53 +02:00
Niels Dossche
764154dc75 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18990, bug #81029, bug #47314: SOAP HTTP socket not closing on object destruction
  Fix leak when path is too long in ZipArchive::extractTo()
  curl: Remove incorrect string release on error
2025-07-02 18:46:37 +02:00
Niels Dossche
09c223de00 Fix leak when path is too long in ZipArchive::extractTo()
I did not find an easy way to trigger this branch without also
triggering some other error conditions earlier.

Closes GH-19002.
2025-07-02 18:43:25 +02:00
Niels Dossche
029a78813d Simplify callers of zval_try_get_long() (#18830)
Since 2b383848 references are handled properly by the Zend API, so we
can simplify the callers by removing reference handling from there.
2025-06-12 17:49:22 +02:00
Calvin Buckley
76791e90b9 Use win32 glob implementation on all platforms (#18164)
* Move glob to main/ from win32/

In preparation to make the Win32 reimplementation the standard
cross-platform one. Currently, it doesn't do that and just passes
through the original glob implementation. We could consider also having
an option to use the standard glob for systems that have a sufficient
one.

* Enable building with win32 glob on non-windows

Kind of broken. We're namespacing the function and struct, but not yet
the GLOB_* defines. There are a lot of places callers check if i.e.
NOMATCH is defined that would likely become redundant.

Currently it also has php_glob and #defines glob php_glob (etc.) - I
suspect doing the opposite and changing the callers would make more
sense, just doing MVP to geet it to build (even if it fails tests).

* Massive first pass at conversion to internal glob

Have not tested yet. the big things are:

- Should be invisible to userland PHP code.
- A lot of :%s/GLOB_/PHP_GLOB_/g; the diff can be noisy as a result,
  especially in comments.
- Prefixes everything with PHP_ to avoid conflicts with system glob in
  case it gets included transitively.
- A lot of weird shared definitions that were sprawled out to other
  headers are now included in php_glob.h.
- A lot of (but not yet all cases) of HAVE_GLOB are removed, since we
  can always fall back to php_glob.
- Using the system glob is not wired up yet; it'll need more shim
  ifdefs for each flag type than just glob_t/glob/globfree defs.

* Fix inclusion of GLOB_ONLYDIR

This is a GNU extension, but we don't need to implement it, as the GNU
implementation is flawed enough that callers have to manually filter it
anyways; just provide a stub definition for the constant.

We could consideer implementing this properly later. For now, fixes the
basic glob constant tests.

* Remove HAVE_GLOBs

We now always have a glob implementation that works. HAVE_GLOB should
only be used to check if we have a system implementation, for if we
decide to wrap the system implementation instead.

* We don't need to care about being POSIXly correct for internal glob

* Check for reallocarray

Ideally temporary until GH-17433.

* Forgot to move this file from win32/ to main/

* Check for issetugid (BSD function)

* Allow using the system glob with --enable-system-glob

* Style fix after removing ifdef

* Remove empty case for system glob
2025-05-20 16:20:59 -03:00
Niels Dossche
5f97728780 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix IntlDateFormatter::parseToCalendar() reference type system breaks
  datefmt_parse/datefmt_localtime references type system fixes
  Fix GH-18438: Handling of empty data and errors in ZipArchive::addPattern
2025-04-27 11:33:33 +02:00
Niels Dossche
d00adca199 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  datefmt_parse/datefmt_localtime references type system fixes
  Fix GH-18438: Handling of empty data and errors in ZipArchive::addPattern
2025-04-27 11:32:57 +02:00
Niels Dossche
2eb3100dca Fix GH-18438: Handling of empty data and errors in ZipArchive::addPattern
There is a ZPP arginfo violation because the empty return or error
return is not always properly handled.
And there is also a memory leak if creating the regular expression
instance fails.

Closes GH-18438.
2025-04-27 11:30:57 +02:00
Niels Dossche
1ec9041bf8 Fix reference handling in cancel callback (#18439)
Broke in 8765e9f5e7
2025-04-27 11:27:18 +02:00
Niels Dossche
a7cc447b28 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18431: Registering ZIP progress callback twice doesn't work
2025-04-26 14:27:15 +02:00
Niels Dossche
5b8db66227 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18431: Registering ZIP progress callback twice doesn't work
2025-04-26 14:23:54 +02:00
Niels Dossche
b066ac0b23 Fix GH-18431: Registering ZIP progress callback twice doesn't work
Libzip already cleans up the previous callback, so when that means:
1. The callback zval being already copied over the previous one causes
   libzip to clean up the new callback object. This is the root cause.
2. Our own code to clean the old callback is redundant.

Closes GH-18432.
2025-04-26 14:21:03 +02:00
Niels Dossche
4f10973853 Remove always-false intern checks (#18433) 2025-04-26 14:11:37 +02:00
Niels Dossche
b50f7c22c3 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix memory leak when handling a too long path in ZipArchive::addGlob()
  Fix uouv when handling empty options in ZipArchive::addGlob()
2025-04-16 10:46:23 +02:00
Niels Dossche
ecd2872cf4 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak when handling a too long path in ZipArchive::addGlob()
  Fix uouv when handling empty options in ZipArchive::addGlob()
2025-04-16 10:46:17 +02:00