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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 - 3 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC