Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ PHP NEWS
. Fixed bug GH-15375 (Nested "yield from" skips items after a valid() or
next() call on the inner generator). (iliaal)

- Intl:
. Fixed a crash when converting with a cloned UConverter that uses
toUCallback/fromUCallback. (iliaal)

- Opcache:
. Fixed opcache.protect_memory race under ZTS. (realFlowControl)

Expand Down
3 changes: 3 additions & 0 deletions ext/intl/converter/converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@ static zend_object *php_converter_clone_object(zend_object *object) {

zend_objects_clone_members(&(objval->obj), &(oldobj->obj));

php_converter_resolve_callback(&objval->to_cache, &objval->obj, ZEND_STRL("toUCallback"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- a/ext/intl/converter/converter.c
+++ b/ext/intl/converter/converter.c
@@ -546,8 +546,6 @@ PHP_METHOD(UConverter, __construct) {
              ZEND_ASSERT(EG(exception));
              goto cleanup;
      }
-     php_converter_resolve_callback(&objval->to_cache, Z_OBJ_P(ZEND_THIS), ZEND_STRL("toUCallback"));
-     php_converter_resolve_callback(&objval->from_cache, Z_OBJ_P(ZEND_THIS), ZEND_STRL("fromUCallback"));
 cleanup:
      INTL_G(use_exceptions) = old_use_exception;
      INTL_G(error_level) = old_error_level;
@@ -916,6 +914,8 @@ static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converte
      zend_object_std_init(&objval->obj, ce);
      object_properties_init(&objval->obj, ce);
      intl_error_init(&(objval->error));
+     php_converter_resolve_callback(&objval->to_cache, &objval->obj, ZEND_STRL("toUCallback"));
+     php_converter_resolve_callback(&objval->from_cache, &objval->obj, ZEND_STRL("fromUCallback"));

      *pobjval = objval;

php_converter_resolve_callback(&objval->from_cache, &objval->obj, ZEND_STRL("fromUCallback"));

/* Newly cloned object deliberately does not inherit error state from original object */

return retval;
Expand Down
24 changes: 24 additions & 0 deletions ext/intl/tests/uconverter_clone_callback.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Cloned UConverter resolves toUCallback/fromUCallback on the clone
--EXTENSIONS--
intl
--FILE--
<?php

class MyConverter extends UConverter {
public int $hits = 0;

public function toUCallback($reason, $source, $codeUnits, &$error): string|int|array|null {
$this->hits++;
return parent::toUCallback($reason, $source, $codeUnits, $error);
}
}

$orig = new MyConverter('ascii', 'utf-8');
$clone = clone $orig;
$clone->convert("irregul\xC1\xA1r");
echo $clone->hits > 0 ? "ok\n" : "no callback\n";

?>
--EXPECT--
ok
Loading