Skip to content

Reference invariant broken in mb_convert_variables() #16261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YuanchengJiang opened this issue Oct 6, 2024 · 1 comment
Closed

Reference invariant broken in mb_convert_variables() #16261

YuanchengJiang opened this issue Oct 6, 2024 · 1 comment

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
class Test {
public string $x;
}
$test = new Test;
$ref = "";
$test->x =& $ref;
$fusion = $test;
$b = array(&$fusion);
$c = &$b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);

Resulted in this output:

/php-src/Zend/zend_variables.c:73: void zend_reference_destroy(zend_reference *): Assertion `!((ref)->sources.ptr != ((void*)0))' failed.
Aborted (core dumped)

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

@nielsdos
Copy link
Member

nielsdos commented Oct 6, 2024

One of the legacy code places that incorrectly sets references, I'll check it out.

@nielsdos nielsdos self-assigned this Oct 6, 2024
@nielsdos nielsdos changed the title Assertion failure in Zend/zend_variables.c:73 Reference invariant broken in mb_convert_variables() Oct 6, 2024
nielsdos added a commit to nielsdos/php-src that referenced this issue Oct 6, 2024
The behaviour is weird in the sense that the reference must get
unwrapped. What ended up happening is that when destroying the old
reference the sources list was not cleaned properly. We add handling for
that. Normally we would use use ZEND_TRY_ASSIGN_STRINGL but that doesn't
work here as it would keep the reference and change values through
references (see bug #26639).
nielsdos added a commit that referenced this issue Oct 7, 2024
* PHP-8.2:
  Fix GH-16261: Reference invariant broken in mb_convert_variables()
nielsdos added a commit that referenced this issue Oct 7, 2024
* PHP-8.3:
  Fix GH-16261: Reference invariant broken in mb_convert_variables()
nielsdos added a commit that referenced this issue Oct 7, 2024
* PHP-8.4:
  Fix GH-16261: Reference invariant broken in mb_convert_variables()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants