1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 01:02:25 +01:00
Commit Graph

63919 Commits

Author SHA1 Message Date
Niels Dossche
2ef1930ad3 Fix number of elements after packed hash filling (#11022)
After a hash filling routine the number of elements are set to the fill
index. However, if the fill index is larger than the number of elements,
the number of elements are no longer correct. This is observable at
least via count() and var_dump(). E.g. the attached test case would
incorrectly show int(17) instead of int(11).

Solve this by only increasing the number of elements by the actual
number that got added. Instead of adding a variable that increments per
iteration, I wanted to save some cycles in the iteration and simply
compute the number of added elements at the end.

I discovered this behaviour while fixing GH-11016, where this filling
routine is easily exposed to userland via a specialised VM path [1].
Since this seems to be more a general problem with the macros, and may
be triggered outside of the VM handlers, I fixed it in the macros
instead of modifying the VM to fixup the number of elements.

[1] b2c5acbb01/Zend/zend_vm_def.h (L6132-L6141)
2023-04-06 21:54:59 +02:00
George Peter Banyard
7d93ef067f Convert char* + size_t parameters to zend_string* in phar_find_in_include_path() 2023-04-06 14:56:42 +01:00
George Peter Banyard
8e51cfe0ae Use zend_string_concat helper instead of strpprintf 2023-04-06 14:56:42 +01:00
George Peter Banyard
06896d1c45 Improve locality of stream variable 2023-04-06 14:56:42 +01:00
George Peter Banyard
96ffdd492c size variable is only used once, move closer to usage
Also change type to ssize_t as this is what the function returns
2023-04-06 14:56:42 +01:00
George Peter Banyard
3fb63f7fa2 Extract common code for phar IO intercept functions
Also convert filename to a zend_string*.

This in preparation for refactoring phar_find_in_include_path() to use a zend_string*
2023-04-06 14:56:42 +01:00
George Peter Banyard
1c276aacae Use zend_call_known_instance_method() instead of building FCI/FCC in serializer subroutine (#9955)
Co-authored-by: Tyson Andre <tyson.andre@uwaterloo.ca>
2023-04-06 14:49:29 +01:00
Ilija Tovilo
9a250cc9d6 Add separate static property through trait if parent already declares it
Fixes GH-10935
Closes GH-10937
2023-04-06 14:27:24 +02:00
Niels Dossche
ebf86d284e Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-9397: exif read : warnings and errors : Potentially invalid endianess, Illegal IFD size and Undefined index
2023-04-05 21:41:41 +02:00
Niels Dossche
2d2cf3b6e0 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9397: exif read : warnings and errors : Potentially invalid endianess, Illegal IFD size and Undefined index
2023-04-05 21:37:48 +02:00
Niels Dossche
b81ce297a1 Fix GH-9397: exif read : warnings and errors : Potentially invalid endianess, Illegal IFD size and Undefined index
Don't misinterpret DJI info maker note as DJI maker note.

The DJI and DJI info maker note both share the "DJI" make string.
This caused the current code to try to interpret the DJI info maker note
as a DJI maker note. However, the DJI info maker note requires custom
parsing. Therefore, the misinterpretation actually caused the current
code to believe that there was an unrecoverable error in the IFD for the
maker note by returning false in the maker note parser. This in turn
caused the inability to parse other EXIF metadata.

This patch adds the identification of the DJI info maker note so that it
cannot be misinterpreted. Since we don't implement custom parsing, it
achieves this by setting the tag list to a special marker value (in this
case the NULL pointer). When this marker value is detected, the function
will just skip parsing the maker note and return true. Therefore, the
other code will believe that the IFD is not corrupt.

This approach is similar to handing an unrecognised maker note type
(see the loop on top of exif_process_IFD_in_MAKERNOTE() which also
returns true and treats it as a string). The end result of this patch
is that the DJI info maker note is considered as unknown to the caller of
exif_process_IFD_in_MAKERNOTE(), and therefore that the other EXIF
metadata can be parsed successfully.

Also fix debug output typos in exif.

Closes GH-10470.
2023-04-05 21:35:19 +02:00
Dmitry Stogov
d5484bf115 Remove includes 2023-04-04 22:48:26 +03:00
Dmitry Stogov
e1c6fb76c0 JIT support for delayed destructor for zend_assign_to_typed_ref/prop 2023-04-04 18:55:47 +02:00
Dmitry Stogov
24acb4f134 Delay destructor for zend_std_write_property 2023-04-04 18:55:47 +02:00
Joan Miquel
9e8614233c Add ngx-php to opcache supported sapis (#11013)
This SAPI embed PHP in Nginx server.
https://github.com/rryqszq4/ngx-php

And in the Techempower benchmarks, it's the fastest PHP SAPI.
https://www.techempower.com/benchmarks/#section=data-r20
2023-04-04 16:58:59 +02:00
Niels Dossche
44b1619370 Cleanup pubkey checks in ext/phar (#11009)
These checks are always true because we bail out early if pubkey is
NULL or empty.
But by having these checks, it makes the code more confusing because it
implies pubkey can be false, while it can in fact not.
2023-04-04 10:04:59 +02:00
Máté Kocsis
f42992f580 Remove name field from the zend_constant struct (#10954)
As global constant names are case-sensitive now, we don't have to store them separately above the constant table.
2023-04-03 22:13:47 +02:00
Niels Dossche
fb5e77b636 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect error handling in dom_zvals_to_fragment()
2023-04-03 21:32:23 +02:00
Niels Dossche
94a00e9ecd Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect error handling in dom_zvals_to_fragment()
2023-04-03 21:24:58 +02:00
Niels Dossche
0579beb842 Fix incorrect error handling in dom_zvals_to_fragment()
Discovered this pre-existing problem while testing GH-10682.
Note: this problem existed *before* that PR.

* Not all paths throw a hierarchy request error
* xmlFreeNode must be used instead of xmlFree for the fragment to also
  free its children.
* Free up nodes that couldn't be added when xmlAddChild fails.

I unified the error handling code that's exactly the same with a goto to
prevent at least some of such problems in the future.

Closes GH-10981.
2023-04-03 21:21:35 +02:00
Dmitry Stogov
9a8123142e Merge branch 'PHP-8.2'
* PHP-8.2:
  Tracing JIT: Fixed incorrect code generation fofr SEND-ing of result of ASSIGN to typed reference
2023-04-03 18:15:59 +03:00
Dmitry Stogov
962aac698e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Tracing JIT: Fixed incorrect code generation fofr SEND-ing of result of ASSIGN to typed reference
2023-04-03 18:15:46 +03:00
Dmitry Stogov
8a749c79d0 Tracing JIT: Fixed incorrect code generation fofr SEND-ing of result of ASSIGN to typed reference 2023-04-03 18:15:41 +03:00
Ilija Tovilo
fc88f155be Add zend_alloc XLEAK support
In the future we may want to use a different exit code to warn for tests that
didn't leak.

Closes GH-10999
2023-04-03 12:55:26 +02:00
Ilija Tovilo
50f58c8923 Add ASAN XLEAK support
Only disable LSAN instead of skipping the test. This way we can still detect
memory issues which is arguably more important anyway.

Closes GH-10996
2023-04-03 08:02:19 +02:00
Alex Dowad
c211e67b4e Remove XFAIL from test cases for mb_strcut when used with JIS or ISO-2022-JP encoding
The documentation for mb_strcut states:

    mb_strcut(
        string $string,
        int $start,
        ?int $length = null,
        ?string $encoding = null
    ): string

    mb_strcut() extracts a substring from a string similarly to mb_substr(),
    but operates on bytes instead of characters. If the cut position happens
    to be between two bytes of a multi-byte character, the cut is performed
    starting from the first byte of that character.

My understanding of the $length parameter for mb_strcut is that it
specified the range of bytes to extract from $string, and that all
characters encoded by those bytes should be included in the returned
string, even if that means the returned string would be longer than
$length bytes. This can happen either if 1) there is more than one way
to encode the same character in $encoding, and one way requires more
bytes than the other, or 2) $encoding uses escape sequences.

However, discussion with users of mb_strcut indicates that many of them
interpret $length as the maximum length of the *returned* string.
This is also the historical behavior of the function.

Hence, there is no need to modify the behavior of mb_strcut and then
remove XFAIL from these test cases afterwards. We can keep the current
behavior.
2023-04-02 13:52:14 +02:00
Niels Dossche
3ab6e76ed8 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:23:57 +02:00
Niels Dossche
dd29b66dfa Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
This is a variant of GH-10200, but in a different place.
Basically, simplexml may create a properties table that's packed instead
of associative. But the macro that was used to loop over the properties
table assumed that it was always associative. Replace it by the macro
that figures it out automatically which one of the two it is.

For test: Co-authored-by: jnvsor

Closes GH-10984.
2023-04-01 20:19:14 +02:00
Niels Dossche
0d12b3db64 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:04:48 +02:00
Niels Dossche
79c5b32d15 Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
We should dereference the values, otherwise references don't work.

Closes GH-10991.
2023-04-01 19:44:43 +02:00
Ilija Tovilo
fced34ee1d Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
2023-03-31 14:42:44 +02:00
Ilija Tovilo
d1fc88c726 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
2023-03-31 14:42:35 +02:00
Ilija Tovilo
66ce205718 Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
The ZVAL_ARR macro always set the zval type_info to IS_ARRAY_EX, even if the
hash table is immutable. Since in preg_replace_callback_array() we can return
the passed array directly, and that passed array can be immutable, we need to
reset the type_flags to keep the VM from performing ref-counting on the array.

Fixes GH-10968
Closes GH-10970
2023-03-31 14:41:41 +02:00
Niels Dossche
930db2b2d3 Merge branch 'PHP-8.2'
* PHP-8.2:
  Handle indirect zvals and use up-to-date properties in SplFixedArray::__serialize
  [ci skip] NEWS
2023-03-30 22:07:48 +02:00
Niels Dossche
47b3fe4710 Handle indirect zvals and use up-to-date properties in SplFixedArray::__serialize
Closes GH-10925.
2023-03-30 21:43:39 +02:00
Niels Dossche
da96aa8868 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix bug #80602: Segfault when using DOMChildNode::before()
2023-03-30 20:56:57 +02:00
Niels Dossche
4b3eb0b048 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix bug #80602: Segfault when using DOMChildNode::before()
2023-03-30 20:50:23 +02:00
NathanFreeman
2d6decc14c Fix bug #80602: Segfault when using DOMChildNode::before()
This furthermore fixes the logic error explained in
https://github.com/php/php-src/pull/8729#issuecomment-1161737132

Closes GH-10682.
2023-03-30 20:49:05 +02:00
Jakub Zelenka
c0b89e064c Merge branch 'PHP-8.2' 2023-03-30 13:36:14 +01:00
Jakub Zelenka
e80073d3d2 Fix GH-10406: feof() behavior change for UNIX based socket resources
This change restores the old behaviour for the server socket streams
that don't support IO. This is now stored in the stream flags so it can
be later used to do some other decisions and possibly introduce some
better error reporting.

Closes GH-10877
2023-03-30 13:31:46 +01:00
Niels Dossche
b606e44abc Silence compiler warnings in ext/sockets/conversions.c (#10974)
These values will be initialised, but the compiler can't see it.
Write a dummy value to silence this.

Closes GH-10959.
2023-03-29 22:18:29 +02:00
David CARLIER
717f460fa4 ext/posix: posix_eaccess little update and forgotten UPGRADING entry. (#10965) 2023-03-29 20:08:42 +01:00
Niels Dossche
efdbb4715e Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix uninitialized variable accesses in sockets/conversions
2023-03-29 19:52:25 +02:00
Niels Dossche
8a1cbdd7df Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix uninitialized variable accesses in sockets/conversions
2023-03-29 19:47:38 +02:00
Niels Dossche
b8755a7559 Fix uninitialized variable accesses in sockets/conversions
This was first pointed out in GH-10959.
The from_zval_... functions don't always write to the pointer, in particular
it is necessary to check for an error before using the value. Otherwise
we can access an uninitialized value and that's UB (and dangerous).

Note: this does *NOT* get rid of the compiler warning. Even though there
is error checking now, the compiler isn't smart enough to figure out
that the values can not be used uninitialized.

Closes GH-10966.
2023-03-29 19:44:30 +02:00
Derick Rethans
2f309dee8e Updated to version 2023.3 (2023c) 2023-03-29 10:06:02 +01:00
Derick Rethans
3ec02202fd Updated to version 2023.3 (2023c) 2023-03-29 10:06:01 +01:00
Derick Rethans
bb7dd51f7a Updated to version 2023.3 (2023c) 2023-03-29 10:06:00 +01:00
Niels Dossche
f8ecb80e84 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix undefined behaviour in unpack()
2023-03-28 22:48:21 +02:00
Niels Dossche
e9195b21cc Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix undefined behaviour in unpack()
2023-03-28 22:43:53 +02:00