Commit Graph

144 Commits

Author SHA1 Message Date
Niels Dossche
ec8a24f746
Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] 35c8a010c6/Zend/zend_object_handlers.h (L231C1-L231C64)

Closes GH-16401.
2024-10-14 19:23:04 +02:00
Niels Dossche
c0de7214aa
Fix GH-14286 (ffi enum type (when enum has no name) make memory leak)
For top-level anonymous type definition we never store the declaration anywhere
else nor the type anywhere else.
The declaration keeps owning the type and it goes out of scope.
For anonymous fields this gets handled by the add_anonymous_field code that
removes the type from the declaration.
This patch does something similar in the parsing code when it is
detected we're dealing with an anonymous enum in a top-level declaration.

Closes GH-14839.
2024-07-22 17:44:47 +02:00
Arnaud Le Blanc
1ff277dee2
Fix is_zend_ptr() for huge blocks (#14626)
is_zend_ptr() expected zend_mm_heap.huge_list to be circular, but it's in fact NULL-terminated. It could crash when at least one huge block exists and the ptr did not belong to any block.
2024-06-25 15:14:00 +02:00
Niels Dossche
ebd1a36670
Fix GH-14215: Cannot use FFI::load on CRLF header file with apache2handler
Some modules may reset _fmode, which causes mangling of line endings.
Always be explicit like we do in other places where the native open call
is used.

Closes GH-14218.
2024-05-14 19:49:22 +02:00
Bob Weinand
e7462bff19
Run one testsuite with observers enabled in CI (#13869)
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2024-04-02 18:11:02 +02:00
Niels Dossche
c727f29942 Fix GH-12905: FFI::new interacts badly with observers
Because these functions are copied and not properly registered (which we
can't), the observer code doesn't add the temporaries on startup.
Add them via a callback during startup.

Closes GH-12906.
2023-12-19 15:59:01 +01:00
Jakub Zelenka
40ccc8ea7e
Fix GH-9698: stream_wrapper_register crashes with FFI\CData provided as class
Closes GH-12926
2023-12-15 14:11:56 +00:00
Arnaud Le Blanc
7a617ee223 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix segfault caused by weak references to FFI objects (#12488)
2023-10-28 15:03:17 +02:00
sji
04b35a44ce
Fix segfault caused by weak references to FFI objects (#12488)
Thank you!
2023-10-28 14:59:06 +02:00
Ilija Tovilo
88fab26365
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix leaking definitions on FFI::cdef()->new()
2023-07-21 10:42:42 +02:00
Ilija Tovilo
11d6bea98a
Fix leaking definitions on FFI::cdef()->new()
Previously, FFI_G(symbols) and FFI_G(tags) were never cleaned up when calling
new on an existing object. However, if cdef() is called without parameters these
globals are NULL and might be created when new() creates new definitions. These
would then be discarded without freeing them.

Closes GH-11751
2023-07-21 10:42:19 +02:00
Ilija Tovilo
69c57bea3d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Reset EG(trampoline).op_array.last_var that FFI may modify
2023-03-27 22:59:58 +02:00
Ilija Tovilo
4e0bd03681
Reset EG(trampoline).op_array.last_var that FFI may modify
Closes GH-10916
2023-03-27 22:59:00 +02:00
Dmitry Stogov
cec528d06b Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix assertion failure when var_dump'ing void FFI result (#10568)
2023-02-13 22:38:43 +03:00
Niels Dossche
1a5fc6e1a3
Fix assertion failure when var_dump'ing void FFI result (#10568) 2023-02-13 22:38:28 +03:00
Tyson Andre
e3f04ddb0b Merge branch 'PHP-8.1' into PHP-8.2 2023-02-03 09:18:03 -05:00
Tyson Andre
fe2dc2b481
Avoid crash for reset/end/next/prev() on ffi classes (#9711)
(And any PECLs returning `zend_empty_array` in the handler->get_properties
overrides)

Closes GH-9697

This is similar to the fix used in d9651a9419
for array_walk.

This should make it safer for php-src (and PECLs, long-term) to return
the empty immutable array in `handler->get_properties` to avoid wasting memory.
See https://github.com/php/php-src/issues/9697#issuecomment-1273613175

The only possible internal iterator position for the empty array is at the end
of the empty array (nInternalPointer=0).
The `zend_hash*del*` helpers will always set nInternalPointer to 0 when an
array becomes empty,
regardless of previous insertions/deletions/updates to the array.
2023-02-03 09:17:33 -05:00
Dmitry Stogov
d5b307c434 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect bitshifting and masking in ffi bitfield (#10403)
2023-01-24 09:15:27 +03:00
Niels Dossche
560ca9c7ae
Fix incorrect bitshifting and masking in ffi bitfield (#10403)
When a uint8_t is bitshifted to the left, it is actually promoted to an
int. For the current code this has the effect of a wrong sign-extension,
and the result will also wrongly become zero when insert_pos >= 32.
Fix this by adding an explicit cast.
Furthermore, the partial prefix byte mask was computed incorrectly: the
byte is already shifted so the mask should not account for the shift.
2023-01-24 09:15:03 +03:00
Ilija Tovilo
b08901b63f
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Migrate i386 to GitHub actions
2022-11-03 14:37:59 +01:00
Ilija Tovilo
ed1e703716
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Migrate i386 to GitHub actions
2022-11-03 14:37:17 +01:00
Ilija Tovilo
75970077b0
Migrate i386 to GitHub actions
Closes GH-9856
2022-11-03 14:34:54 +01:00
Dmitry Stogov
626e909877 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
2022-10-10 11:25:33 +03:00
Dmitry Stogov
fa2c519544 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array
2022-10-10 11:25:23 +03:00
Dmitry Stogov
d9651a9419 Fix GH-9697: array_walk($ffiInstance, function () {}) crashes due to expecting mutable array 2022-10-10 11:21:05 +03:00
Dmitry Stogov
04d5faed23 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix order of checks to throw exception with better message
2022-08-11 09:32:18 +03:00
Dmitry Stogov
18183ff9c7 Fix order of checks to throw exception with better message
This clarifies the "->cdata" meaning.
2022-08-11 09:30:47 +03:00
Adam Saponara
8cf9c2f200
Fix GH-9090: Support assigning function pointers in FFI
Closes GH-9107.
2022-07-27 10:42:25 +02:00
Bob Weinand
ff6b813557 Merge branch 'PHP-8.0' into PHP-8.1 2022-04-24 18:04:37 +02:00
Bob Weinand
a74b865123 Add missing SKIPIF for new ext/ffi test 2022-04-24 18:02:46 +02:00
Bob Weinand
01b91cb3b1 Merge branch 'PHP-8.0' into PHP-8.1 2022-04-24 14:53:51 +02:00
Bob Weinand
2397e7685e Fix GH-8433: Assigning function pointers to structs in FFI leaks memory 2022-04-24 14:53:18 +02:00
Christoph M. Becker
1632ebb542
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-7867: FFI::cast() from pointer to array is broken
2022-01-10 23:59:55 +01:00
Christoph M. Becker
703cac33db
Fix GH-7867: FFI::cast() from pointer to array is broken
Casting from pointer to array is special, so we must not fall back to
the general FFI casting.  There is a particular issue regarding the
size comparison, namely that the pointer size is always 8 for 64bit
architectures, but the size of an array is determined by its
declaration, so as is casting a pointer to an array with more than 8
elements would fail, but casting to an array with less than 9 elements
succeeds, but the internal pointer would point to some arbitrary
memory.

We fix this by properly supporting the cast.  An alternative would be
to deny this kind of cast generally, since it is not necessarily safe.
However, FFI isn't necessarily safe anyway.

We also check pointer/array type compatibility when casting.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-7876.
2022-01-10 23:58:39 +01:00
Dmitry Stogov
b4a5bc4a62 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed error message
2021-09-15 15:01:08 +03:00
Dmitry Stogov
23327bf4b3 Fixed error message 2021-09-15 15:00:49 +03:00
Dmitry Stogov
6f65a1b263 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed error message
2021-09-15 14:59:14 +03:00
Dmitry Stogov
de20a89b06 Fixed error message 2021-09-15 14:58:55 +03:00
Dmitry Stogov
46c09a34d5 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined)
2021-09-15 14:53:00 +03:00
Dmitry Stogov
594cba7f8e Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined)
2021-09-15 14:49:35 +03:00
Dmitry Stogov
0badc7de96 Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined) 2021-09-15 14:48:33 +03:00
Bob Weinand
1440d15e00
Add missing zend_test requirement to ffi test for bug80847 2021-08-18 17:16:54 +02:00
Tyson Andre
efbdcb8e49
Rename FFI getFuncArg* to getFuncParameter*, $arg_index->$index (#7236)
PHP is already already using "Parameter" instead of "Argument" for reflection on types elsewhere.

Parameter is used to refer to the function declarations
(AST_PARAM internally in the AST, ReflectionFunctionAbstract->getParameters(),
etc.)
Argument is used to refer to expressions passed to the functions by the caller
(ArgumentCountError, etc.).
(Error messages were also changed in php 8.x to refer to passing too many arguments to a
function)

Other languages use similar definitions,
e.g. https://developer.mozilla.org/en-US/docs/Glossary/Parameter
2021-07-14 09:12:25 -04:00
Dmitry Stogov
a2845e32cb FFI::CType reflection API 2021-07-13 13:13:51 +03:00
Nikita Popov
1cba7764b4
Remove zend_atoi() (#7232)
It's the same as (int) zend_atol() -- it doesn't try to do anything
integer size specific. Canonicalize to one function in preparation
for renaming zend_atol() to something less misleading.

FFI test is adjusted to use a zend_test function. It just calls
zend_atol() internally, but could really be anything.

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2021-07-13 09:22:31 +02:00
Nikita Popov
62cb7dc4f5 Disable FFI preload tests with opcache.preload_user 2021-05-19 10:36:55 +02:00
Max Semenik
bd9f4fa676 Migrate skip checks to --EXTENSIONS--, p2
For rationale, see https://github.com/php/php-src/pull/6787

Make extension checks lowercase, add a special case for opcache
that has internal name not matching .so filename.

Extensions migrated in part 2:
* dom
* exif
* fileinfo
* ffi
2021-04-01 12:08:24 +01:00
Dmitry Stogov
6800f0a3c2 XFAIL on WIN64 because of problem in libffi
(cherry picked from commit 6689bedd17)
2021-03-24 13:57:31 +01:00
Dmitry Stogov
6689bedd17 XFAIL on WIN64 because of problem in libffi 2021-03-19 12:19:24 +03:00
Dmitry Stogov
c8a8c47f7e Merge branch 'PHP-8.0'
* PHP-8.0:
  Additional fix for bug #80847. On x86_64 part of structure may be passed in CPU registers.
2021-03-18 16:16:29 +03:00