Commit graph

728 commits

Author SHA1 Message Date
Niels Dossche
e735d2bc3b
Fix GH-17808: PharFileInfo refcount bug
PharFileInfo just takes a pointer from the manifest without refcounting
anything. If the entry is then removed from the manifest while the
PharFileInfo object still exists, we get a UAF.
We fix this by using the fp_refcount field. This is technically a
behaviour change as the unlinking is now blocked, and potentially file
modifications can be blocked as well. The alternative would be to have a
field that indicates whether deletion is blocked, but similar corruption
bugs may occur as well with file overwrites, so we increment fp_refcount
instead.
This also fixes an issue where a destructor called multiple times
resulted in a UAF as well, by moving the NULL'ing of the entry field out
of the if.

Closes GH-17811.
2025-02-15 13:15:51 +01:00
Niels Dossche
eab209d81d
Fix GH-17518: offset overflow phar extractTo()
`search` can be the empty string, so we need to check the length before
checking the last char.

Closes GH-17519.
2025-01-19 13:05:19 +01:00
Niels Dossche
142f85e2e1
Fix GH-17137: Segmentation fault ext/phar/phar.c
Commit edae2431 attempted to fix a leak and double free, but didn't
properly understand what was going on, causing a reference count mistake
and subsequent segfault in this case.

The first mistake of that commit is that the reference count should've
been increased because we're reusing a phar object. The error handling
path should've gotten changed instead to undo this refcount increase
instead of not refcounting at all (root cause of this bug).

The second mistake is that the alias isn't supposed to be transferred or
whatever, that just doesn't make sense. The reason the test
bug69958.phpt originally leaked is because in the non-reuse case we
borrowed the alias and otherwise we own the alias. If we own the alias
the alias information shouldn't get deleted anyway as that would desync
the alias map.

Fixing these will reveal a third issue in which the alias memory is not
always properly in sync with the persistence-ness of the phar, fix this
as well.

Closes GH-17150.
2024-12-15 13:50:09 +01:00
Niels Dossche
25817ad298
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16406: Assertion failure in ext/phar/phar.c:2808
2024-10-17 21:23:47 +02:00
Niels Dossche
6a8d0a054d
Fix GH-16406: Assertion failure in ext/phar/phar.c:2808
When copying entries during conversion in phar_convert_to_other(), the
header offset is not reset. This didn't matter in the past as it wasn't
used anyway in the particular use-case, but since 1bb2a4f9 this is
actually used and sanity-checked.

Closes GH-16470.
2024-10-17 21:23:17 +02:00
Niels Dossche
7525e690f6 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix #71465: PHAR doesn't know about litespeed
2024-01-03 21:34:59 +01:00
Niels Dossche
85dbbe19e2 Fix #71465: PHAR doesn't know about litespeed
We should perhaps look into a generic system to ask the SAPI whether
a feature should be supported or not. Or, we should look into making
a denylist instead of an allowlist.
Anyway, let's not try doing anything fancy on stable branches.

Closes GH-13070.
2024-01-03 21:31:09 +01:00
Máté Kocsis
840d665583 Deprecate Phar::setStub(resource $stub, int $length) 2023-07-18 12:59:21 +02:00
Ilija Tovilo
38cf52d8aa
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-uninitialized value in phar_object.c
2023-05-08 17:07:04 +02:00
Ilija Tovilo
b71a961363
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use-of-uninitialized value in phar_object.c
2023-05-08 17:06:57 +02:00
Ilija Tovilo
78ec64af44
Fix use-of-uninitialized value in phar_object.c
resource would stay uninitialized if the first call to zend_parse_parameters
fails, but the value is still passed to phar_add_file(). It's not used there if
cont_str is provided and so didn't cause any issues.

Closes GH-11202
2023-05-08 17:06:44 +02:00
Michael Voříšek
f89fe830f2
Minor conditions simplify (#10397) 2023-04-26 15:12:01 +02:00
George Peter Banyard
aae20cd119
ext/phar: Fix recently introduced potential NULL dereferencement segfaults (#11065) 2023-04-12 17:05:03 +01:00
George Peter Banyard
4082d425a9
ext/phar: Remove duplicate cleaning-up code 2023-04-10 13:23:08 +01:00
George Peter Banyard
a72778b45d
ext/phar: Prevent unnecessary known string length computation
Closes GH-11033
2023-04-10 13:23:08 +01:00
Ilija Tovilo
9d5f2f1343
Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +01:00
Su, Tao
edae24313d
Fix GH-10755: Memory leak in phar_rename_archive()
In phar_renmae_archive() context, added one reference but immediately
destroyed another, so do not need to increase refcount. With removal of
refcount++ line, PHP/Zend no longer reports memory leak.
Updated bug69958.phpt test file accordingly.

Closes GH-10856
2023-03-20 13:27:33 +01:00
Max Kellermann
d46dea169c
Make globals const (part 2) (#10610)
* Zend/zend_enum: make `forbidden_methods` static+const

* main/php_syslog: make `xdigits` static

* sapi/fpm: make several globals `const`

* sapi/phpdbg: make `OPTIONS` static

* sapi/phpdbg/help: make help texts const

* sapi/cli: make `template_map` const

* ext/ffi: make `zend_ffi_types` static

* ext/bcmath: make `ref_str` const

* ext/phar: make several globals static+const
2023-02-18 19:52:53 +00:00
Christoph M. Becker
c8955c078a
Revert GH-10220
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491.
This reverts commit 588a07f737.
This reverts commit f377e15751.
This reverts commit b4ba16fe18.
This reverts commit 694ec1deea.
This reverts commit 6b34de8eba.
This reverts commit aa1cd02a43.
This reverts commit 308fd311ea.
This reverts commit 16203b53e1.
This reverts commit 738fb5ca54.
This reverts commit 9fdbefacd3.
This reverts commit cd4a7c1d90.
This reverts commit 928685eba2.
This reverts commit 01e5ffc85c.
2023-01-16 12:27:33 +01:00
George Peter Banyard
5624cbbed1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix wrong flags check for compression method in phar_object.c
  Fix missing check for xmlTextWriterEndElement
  Fix substr_replace with slots in repl_ht being UNDEF
2023-01-15 15:43:57 +00:00
George Peter Banyard
ec377c687d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix wrong flags check for compression method in phar_object.c
  Fix missing check for xmlTextWriterEndElement
  Fix substr_replace with slots in repl_ht being UNDEF
2023-01-15 15:43:34 +00:00
Niels Dossche
347b7c3628
Fix wrong flags check for compression method in phar_object.c
I found this issue using static analysis tools, it reported that the condition was always false.
We can see that flags is assigned in the switch statement above, but a mistake was made in the comparison.

Closes GH-10328

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-15 15:35:35 +00:00
Max Kellermann
308fd311ea ext/{standard,json,random,...}: add missing includes 2023-01-10 14:19:03 +00:00
Niels
7b2c3c11b2
Cleanup redundant lookups in phar_object.c (#10150) 2022-12-22 13:00:28 +00:00
Máté Kocsis
6ab897c8d3
Declare ext/phar constants in stubs (#9094) 2022-07-22 13:09:23 +02:00
George Peter Banyard
7cd8879d77 Refactor spl_filesystem_object_get_path() to return zend_string* 2022-06-23 14:41:24 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Stanislav Malyshev
18ebe1588d
Merge branch 'PHP-8.0'
* PHP-8.0:
  Update NEWS
  Fix #81211: Symlinks are followed when creating PHAR archive
2021-08-23 23:31:00 -07:00
Stanislav Malyshev
33e4174d1c
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Update NEWS
  Fix #81211: Symlinks are followed when creating PHAR archive
2021-08-23 23:30:34 -07:00
Stanislav Malyshev
40db8947e2
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Update NEWS
  Fix #81211: Symlinks are followed when creating PHAR archive
2021-08-23 23:29:01 -07:00
Christoph M. Becker
2ff853aa11
Fix #81211: Symlinks are followed when creating PHAR archive
It is insufficient to check whether the `base` is contained in `fname`;
we also need to ensure that `fname` is properly separated.  And of
course, `fname` has to start with `base`.
2021-08-23 23:25:16 -07:00
Remi Collet
c51af22fef
implement openssl_256 and openssl_512 for phar singatures 2021-08-11 14:13:57 +02:00
Nikita Popov
edb6b375dd Don't return bool from Phar::offsetUnset()
This violates the ArrayAccess interface. Use offsetExists() to
check if an entry exists.
2021-07-16 16:39:27 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Máté Kocsis
83916e83b4
Declare tentative return types for ext/phar (#7052) 2021-05-28 15:07:15 +02:00
Máté Kocsis
0224cc83fc
Merge branch 'PHP-8.0'
* Add a few missing RETURN_THROWS();
* Fix a few ext/phar return types
2021-05-27 16:32:16 +02:00
Máté Kocsis
2d47447d66 Add a few missing RETURN_THROWS();
Only PharFileInfo::compress() really needs it though.
2021-05-27 16:31:18 +02:00
Nikita Popov
f57526a07a Store base path as zend_string in Phar::buildFrom*
This also removes the need to check for length overflow, as the
length is now size_t.
2021-05-27 10:57:51 +02:00
Nikita Popov
8c192c717c Accept regex as zend_string in Phar::buildFromDirectory()
No need to copy it...
2021-05-27 10:51:51 +02:00
George Peter Banyard
e7135cb817
Use zend_string_equals_* API in a couple of more place
Closes GH-6979
2021-05-14 13:45:17 +01:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
George Peter Banyard
5caaf40b43
Introduce pseudo-keyword ZEND_FALLTHROUGH
And use it instead of comments
2021-04-07 00:46:29 +01:00
Dmitry Stogov
c732ab400a Change Zend Stream API to use zend_string* instead of char*.
This allows to eliminate re-calculation of string lenght and hash value.
See the detailed list of changes in UPGRADING.INTERNALS.
2021-03-16 20:31:36 +03:00
Dmitry Stogov
13e4ce386b Improve SPL directory and stat() cache using zend_srting* instead of char* 2021-02-26 02:28:46 +03:00
Máté Kocsis
5b5bfd6be4
Generate class entries from stubs for phar, posix, pspell, readline, reflection, session, shmop
Closes GH-6692
2021-02-15 00:11:22 +01:00
Nikita Popov
ccc70ec5d4 Merge branch 'PHP-8.0'
* PHP-8.0:
  Make Phar $fileNotFoundScript nullable
2021-02-09 12:57:58 +01:00
Nikita Popov
44192ce80b Make Phar $fileNotFoundScript nullable
While "" is already treated the same way as absence, null is the
logically correct default here. Making this one argument non-nullable
is particularly pecular when considering that the preceding $alias
and $index arguments are both nullable.
2021-02-09 12:55:33 +01:00
Christoph M. Becker
e1a1918f26 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #69279: Compressed ZIP Phar extractTo() creates garbage files
2021-01-19 10:31:06 +01:00
Christoph M. Becker
cfae999f1b Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #69279: Compressed ZIP Phar extractTo() creates garbage files
2021-01-19 10:30:28 +01:00
Christoph M. Becker
68f5289e9e Fix #69279: Compressed ZIP Phar extractTo() creates garbage files
When extracting compressed files from an uncompressed Phar, we must not
use the direct file pointer, but rather get an uncompressed file
pointer.

We also add a test to show that deflated and stored entries are
properly extracted.

This also fixes #79912, which appears to be a duplicate of #69279.

Co-authored-by: Anna Filina <afilina@gmail.com>

Closes GH-6599.
2021-01-19 10:28:54 +01:00