Skip to content
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

Unable to resize SplfixedArray after being unserialized in PHP 8.2.15 #13531

Closed
codex-m opened this issue Feb 27, 2024 · 0 comments
Closed

Unable to resize SplfixedArray after being unserialized in PHP 8.2.15 #13531

codex-m opened this issue Feb 27, 2024 · 0 comments

Comments

@codex-m
Copy link

codex-m commented Feb 27, 2024

Description

The following code:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL);

echo "============" . "<br />";
echo "Testing in " . phpversion() . "<br />";
echo "============";
echo "<br /><br />";

/**
 * Create 5 items
 */
$array = new SplFixedArray(5);

/**
 * Get size
 * EXPECTED: 5
 */
$size = $array->getSize();
echo "Original size before serializing. Expected result is 5." . "<br />";
echo "Actual result: $size";
echo "<br /><br />";

/**
 * Serialize SPLFixedArray object
 */
$serialized = serialize($array);

/**
 * Unserialize SPLFixedArray object
 */
$array = unserialize($serialized);

/**
 * Get size
 * EXPECTED: 5
 */
$size = $array->getSize();
echo "Original size after serializing. Expected is still 5." . "<br />";
echo "Actual result is $size";
echo "<br /><br />";
   
/**
 * Resize SPLFixedArray to 6 items
 */
echo "Resizing array to 6 items" . "<br />";
$array->setSize(6);
/**
 * Get size after resize
 * EXPECTED: 6
 */
$size = $array->getSize();
echo "Updated size after resize. " . "<em>" . "Expected is 6." . "</em>" . "<br />";
echo "<strong>" . "Actual result is $size" . "</strong>";
echo "<br />";

Resulted in this output:

============
Testing in 8.2.15
============

Original size before serializing. Expected result is 5.
Actual result: 5

Original size after serializing. Expected is still 5.
Actual result is 5

Resizing array to 6 items
Updated size after resize. Expected is 6.
Actual result is 5

But I expected this output instead:

============
Testing in 8.2.15
============

Original size before serializing. Expected result is 5.
Actual result: 5

Original size after serializing. Expected is still 5.
Actual result is 5

Resizing array to 6 items
Updated size after resize. Expected is 6.
Actual result is 6

Additional notes:

  • This is only reproducible with PHP 8.2.15.
  • It works well with PHP 8.1/8.0/7.4.

I've checked the docs on changes with setSize() method with PHP 8.2. It does not mention that it cannot be used after unserializing. So I open this ticket as it could be a bug. Thank you!

PHP Version

PHP 8.2.15

Operating System

Ubuntu 22.04 LTS

@nielsdos nielsdos self-assigned this Feb 27, 2024
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 27, 2024
…zed in PHP 8.2.15

When unserializing, the cached_resize field was not reset to -1
correctly, causing the setSize() method to think we were inside of a
resize operation.
nielsdos added a commit that referenced this issue Feb 27, 2024
* PHP-8.2:
  Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
nielsdos added a commit that referenced this issue Feb 27, 2024
* PHP-8.3:
  Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
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.

2 participants