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

800 Commits

Author SHA1 Message Date
Gina Peter Banyard
f40b356ad9 Use smart_str_append() if we have a zend_string* (#21414) 2026-03-21 17:06:14 +00:00
David Carlier
77925b971a Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21333: use-after-free when unlinking entries during iteration of a compressed phar.
2026-03-05 22:32:38 +00:00
David Carlier
449361afbf Fix GH-21333: use-after-free when unlinking entries during iteration of a compressed phar.
close GH-21334
2026-03-05 22:31:49 +00:00
Niels Dossche
18c560d573 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix bug #74154: Phar extractTo creates empty files
2025-12-22 12:19:54 +01:00
Niels Dossche
27d4e2f302 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix bug #74154: Phar extractTo creates empty files
2025-12-22 12:19:47 +01:00
Niels Dossche
e90b48c8e5 Fix bug #74154: Phar extractTo creates empty files
The current code causes the phar entry to remain in the fname cache.
This would be fine for uncompressed phars, but is a problem for
compressed phars when they try to reopen the file pointer.
The reopen code will try to use the compressed file pointer as if it
were an uncompressed file pointer. In that case, for the given test, the
file offsets are out of bounds for the compressed file pointer because
they are the uncompressed offsets. This results in empty files.
In other cases, it's possible to read compressed parts of the file that don't
belong to that particular file.
To solve this, we simply remove the phar entry from the fname cache if
the file pointer was closed but the phar is compressed. This will make
sure that reopening the phar will not go through the cache and instead
opens up a fresh file pointer with the right decompression settings.

Closes GH-20754.
2025-12-22 12:19:21 +01:00
Niels Dossche
4f3c28aaac phar: Simplify phar_open_archive_fp() (#20753)
By returning the stream directly, we avoid calling some helpers
functions and it becomes more clear on what stream the code actually
acts upon.
2025-12-22 11:51:31 +01:00
Niels Dossche
0880433e61 Merge branch 'PHP-8.5'
* PHP-8.5:
  phar: Fix SplFileInfo::openFile() in write mode
2025-12-21 13:18:47 +01:00
Niels Dossche
38e8aca77d Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  phar: Fix SplFileInfo::openFile() in write mode
2025-12-21 13:18:39 +01:00
Niels Dossche
cf4e8e0ef6 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  phar: Fix SplFileInfo::openFile() in write mode
2025-12-21 13:18:23 +01:00
Niels Dossche
efde160ef4 phar: Fix SplFileInfo::openFile() in write mode
This stopped working after e735d2bc3b because fp_refcount is increased,
making phar think that the file has open read pointers.
To fix this, the refcount shouldn't be increased but that would
re-introduce the previous bug.
Instead, we need to add a field that "locks" the existence of the
internal entry separate from the refcount.

Closes GH-20473.
2025-12-21 13:17:54 +01:00
Niels Dossche
3e87cfa9c8 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20732: Phar::LoadPhar undefined behavior when loading directory
2025-12-20 11:16:36 +01:00
Niels Dossche
66d4441217 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20732: Phar::LoadPhar undefined behavior when loading directory
2025-12-20 11:16:30 +01:00
Niels Dossche
9686936378 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-20732: Phar::LoadPhar undefined behavior when loading directory
2025-12-20 11:16:13 +01:00
Niels Dossche
22aaa20dab Fix GH-20732: Phar::LoadPhar undefined behavior when loading directory
The size of `got` was incorrect: it being unsigned means that the error
return codes are converted from -1 to SIZE_MAX. We should use ssize_t
instead.

Closes GH-20735.
2025-12-20 11:15:47 +01:00
Niels Dossche
927830da86 phar: Remove unused min_timestamp field (#20617) 2025-11-29 14:36:59 +01:00
Niels Dossche
40ff6e0592 Merge branch 'PHP-8.5'
* PHP-8.5:
  Revert "ext/phar: Voidify flush function as it always returns EOL"
  phar: Fix broken return value of fflush() for phar file entries
2025-11-15 14:05:32 +01:00
Niels Dossche
7809d51918 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Revert "ext/phar: Voidify flush function as it always returns EOL"
  phar: Fix broken return value of fflush() for phar file entries
2025-11-15 13:59:38 +01:00
Niels Dossche
08ec409f1b Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  phar: Fix broken return value of fflush() for phar file entries
2025-11-15 13:58:17 +01:00
Niels Dossche
fd5c14e682 Revert "ext/phar: Voidify flush function as it always returns EOL"
This reverts commit 2513258a2b.
2025-11-15 13:57:47 +01:00
Niels Dossche
2f9d86b677 phar: Fix broken return value of fflush() for phar file entries
The flush functions always return EOF, even in the success path.
The success path should return 0 to indicate success.

Closes GH-20474.
2025-11-15 13:56:06 +01:00
Niels Dossche
a596e05cf3 phar: Make phar_is_tar() and referenced functions const correct (#20451) 2025-11-11 13:44:13 +01:00
Niels Dossche
9d9f979ca1 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20435: SensitiveParameter doesn't work for named argument passing to variadic parameter
  Fix GH-20442: Phar does not respect case-insensitiveness of __halt_compiler() when reading stub
2025-11-10 22:44:21 +01:00
Niels Dossche
5087cf3001 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20435: SensitiveParameter doesn't work for named argument passing to variadic parameter
  Fix GH-20442: Phar does not respect case-insensitiveness of __halt_compiler() when reading stub
2025-11-10 22:44:16 +01:00
Niels Dossche
3e715d3361 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-20435: SensitiveParameter doesn't work for named argument passing to variadic parameter
  Fix GH-20442: Phar does not respect case-insensitiveness of __halt_compiler() when reading stub
2025-11-10 22:43:59 +01:00
Niels Dossche
4ee25395d5 Fix GH-20442: Phar does not respect case-insensitiveness of __halt_compiler() when reading stub
Functions are case insensitive. The flush code already takes this into
account by checking for the __halt_compiler() symbol in a case
insensitive manner; however the parsing code did not do that yet.

Closes GH-20445.
2025-11-10 22:42:32 +01:00
Niels Dossche
425b97e0b6 phar: Remove unused macro (#20343) 2025-10-30 22:45:52 +01:00
Niels Dossche
3a9d59971b phar: Use a loop instead of goto when looking for extensions (#20289)
This gets rid of a TODO and makes the code clearer.
2025-10-25 21:01:28 +02:00
Niels Dossche
752b53ce47 Merge branch 'PHP-8.5'
* PHP-8.5:
  phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
2025-10-21 20:04:48 +02:00
Niels Dossche
c4333a7951 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
2025-10-21 20:04:42 +02:00
Niels Dossche
913327d1fb Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
2025-10-21 20:04:36 +02:00
Niels Dossche
ce0df1a9d8 phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
`filterparams` can leak if `php_stream_fopen_tmpfile()` fails.
To solve this, move the temp file creation first.

Closes GH-20220.
2025-10-21 20:04:13 +02:00
Niels Dossche
63e534d7ca phar: Remove no-op bool casts (#20227)
The field in this struct is already a bool.
2025-10-19 23:29:08 +02:00
Gina Peter Banyard
3828b2426b ext/phar: Refactor phar_create_default_stub() 2025-10-16 21:29:09 +01:00
Gina Peter Banyard
9a24c6a89f ext/phar: assert function are not passed NULL pointers
This simplifies some of the logic and makes the assumptions clear
2025-10-16 21:02:39 +01:00
Gina Peter Banyard
bf44b6ec4e ext/phar/phar.c: use zend_hash_str_exists() instead of fetching ptr and checking for NULL
Especially as the ptr is never used afterwards
2025-10-15 22:36:09 +01:00
Gina Peter Banyard
a5f61654b2 ext/phar: use bool type instead of uint32_t 2025-10-15 22:36:09 +01:00
Gina Peter Banyard
2e62399fc7 ext/phar: use bool type instead of int 2025-10-15 22:36:09 +01:00
Gina Peter Banyard
ebbe64b03a ext/phar: use uint32_t type instead of int 2025-10-15 22:36:09 +01:00
Gina Peter Banyard
6df26b91d0 Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/phar: use size_t type instead of int
2025-10-15 13:37:46 +01:00
Gina Peter Banyard
2bdc7459cf Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/phar: use size_t type instead of int
2025-10-15 13:37:29 +01:00
Gina Peter Banyard
2c514202e1 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  ext/phar: use size_t type instead of int
2025-10-15 13:36:03 +01:00
Gina Peter Banyard
d36109bd71 ext/phar: use size_t type instead of int 2025-10-15 13:35:22 +01:00
Tim Düsterhus
6da93a86f2 zend_API: Remove CHECK*NULL_PATH (#20155)
* tree-wide: Replace `CHECK_NULL_PATH()` by `zend_char_has_nul_byte()`

The former is a direct alias of the latter with a more explicit name and the
former is explicitly documented as a “compatibility” alias.

* tree-wide: Replace `CHECK_ZVAL_NULL_PATH()` by its definition

The former is explicitly documented as a “compatibility” alias.

* zend_API: Remove `CHECK*NULL_PATH`

The `CHECK_ZVAL_NULL_PATH()` macro is unsafe, because it implicitly assumes
that the given `zval*` is `IS_STRING`.

Based on a GitHub search there does not seem to be any user outside of PHP, all
hits were just forks / copies of php-src.
2025-10-15 10:24:22 +02:00
Niels Dossche
44aea65486 phar: Change hacky check into an exception (#20160)
phar_metadata_tracker_unserialize_or_copy() is only ever preceded by
phar_metadata_tracker_has_data() which won't throw.
This check is quite hacky and it should always be the responsibility of
the caller to avoid calling this, even the comment acknowledges this is
a hack.
2025-10-14 18:48:10 +02:00
Niels Dossche
3b54fa4038 Make entry argument nullable for phar_split_fname() to avoid extra allocations (#20146) 2025-10-13 18:47:11 +02:00
Tim Düsterhus
26f88c67e1 phar: Use true / false instead of 1 / 0 for bool parameters
Changes done with Coccinelle:

    @r1@
    identifier F;
    identifier p;
    typedef bool;
    parameter list [n1] PL1;
    parameter list [n2] PL2;
    @@

    F(PL1, bool p, PL2) {
    ...
    }

    @r2@
    identifier r1.F;
    expression list [r1.n1] EL1;
    expression list [r1.n2] EL2;
    @@

    F(EL1,
    (
    - 1
    + true
    |
    - 0
    + false
    )
    , EL2)
2025-09-24 18:51:40 +02:00
Tim Düsterhus
6c4c659997 phar: Use return true / return false for functions returning bool
Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
2025-09-24 18:51:40 +02:00
Niels Dossche
5a2a150829 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix phar crash and file corruption with SplFileObject
2025-07-05 21:44:39 +02:00
Niels Dossche
2aeefb13be Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix phar crash and file corruption with SplFileObject
2025-07-05 21:44:34 +02:00