php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81312 mb_convert_variables() corrupts reference of array element
Submitted: 2021-07-30 03:18 UTC Modified: 2021-08-02 14:33 UTC
From: heguangyu5 at qq dot com Assigned:
Status: Open Package: mbstring related
PHP Version: 7.4.22 OS: ubuntu
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-07-30 03:18 UTC] heguangyu5 at qq dot com
Description:
------------
mb_convert_variables() should only convert enconding of array elements but not change the array structure.

Test script:
---------------
<?php

$a = "‚ ‚¢‚€‚Š‚š";
$b = array(&$a);
$c = $b;

var_dump($a, $b, $c);

$c[0] .= "  abc";

var_dump($a, $b, $c);

mb_convert_variables("EUC-JP", "Shift_JIS", $c);
var_dump($a, $b, $c);

$c[0] .= "  def";

var_dump($a, $b, $c);

Expected result:
----------------
string(10) "‚ ‚¢‚€‚Š‚š"
array(1) {
  [0]=>
  &string(10) "‚ ‚¢‚€‚Š‚š"
}
array(1) {
  [0]=>
  &string(10) "‚ ‚¢‚€‚Š‚š"
}
string(15) "‚ ‚¢‚€‚Š‚š  abc"
array(1) {
  [0]=>
  &string(15) "‚ ‚¢‚€‚Š‚š  abc"
}
array(1) {
  [0]=>
  &string(15) "‚ ‚¢‚€‚Š‚š  abc"
}
string(15) "€¢€€€Š€š€ª  abc"
array(1) {
  [0]=>
  &string(15) "€¢€€€Š€š€ª  abc"
}
array(1) {
  [0]=>
  &string(15) "€¢€€€Š€š€ª  abc"
}
string(20) "€¢€€€Š€š€ª  abc  def"
array(1) {
  [0]=>
  &string(20) "€¢€€€Š€š€ª  abc  def"
}
array(1) {
  [0]=>
  &string(20) "€¢€€€Š€š€ª  abc  def"
}

Actual result:
--------------
string(10) "‚ ‚¢‚€‚Š‚š"
array(1) {
  [0]=>
  &string(10) "‚ ‚¢‚€‚Š‚š"
}
array(1) {
  [0]=>
  &string(10) "‚ ‚¢‚€‚Š‚š"
}
string(15) "‚ ‚¢‚€‚Š‚š  abc"
array(1) {
  [0]=>
  &string(15) "‚ ‚¢‚€‚Š‚š  abc"
}
array(1) {
  [0]=>
  &string(15) "‚ ‚¢‚€‚Š‚š  abc"
}
string(15) "‚ ‚¢‚€‚Š‚š  abc"
array(1) {
  [0]=>
  &string(15) "‚ ‚¢‚€‚Š‚š  abc"
}
array(1) {
  [0]=>
  string(15) "€¢€€€Š€š€ª  abc"
}
string(15) "‚ ‚¢‚€‚Š‚š  abc"
array(1) {
  [0]=>
  &string(15) "‚ ‚¢‚€‚Š‚š  abc"
}
array(1) {
  [0]=>
  string(20) "€¢€€€Š€š€ª  abc  def"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-02 14:33 UTC] nikic@php.net
The current behavior is tested in https://github.com/php/php-src/blob/master/ext/mbstring/tests/bug26639.phpt.

Though the original bug report (https://bugs.php.net/bug.php?id=26639) doesn't talk about references, but only missing copy-on-write.

I'm includes to agree that the current behavior is incorrect.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Oct 07 13:05:54 2022 UTC