Skip to content
Merged
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
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ memcached or similar memory based storages for serialized data.</description>
and use that instead of creating a brand new string.
(This deliberately doesn't create a new interned string if one doesn't already exist.)
(Before this change, igbinary would deduplicate strings when serializing, but would not check if strings were interned by PHP itself when unserializing)
* Avoid debug build assertion failure for `HT_ASSERT_RC1` the same way as PHP's unserialize - this is a case where ostensibly there are no other references to the array being unserialized.
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -210,6 +211,7 @@ memcached or similar memory based storages for serialized data.</description>
<file name="igbinary_094.phpt" role="test" />
<file name="igbinary_095.phpt" role="test" />
<file name="igbinary_096.phpt" role="test" />
<file name="igbinary_097.phpt" role="test" />
<file name="igbinary_bug54662.phpt" role="test" />
<file name="igbinary_bug72134.phpt" role="test" />
<file name="igbinary_enums_1.phpt" role="test" />
Expand Down
6 changes: 6 additions & 0 deletions src/php7/igbinary.c
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,12 @@ inline static int igbinary_unserialize_array(struct igbinary_unserialize_data *i
}
array_init_size(z_deref, n);
h = Z_ARRVAL_P(z_deref);
#if PHP_VERSION_ID >= 70200
/* The array may contain references to itself, in which case we'll be modifying an
* rc>1 array. This is okay, since the array is, ostensibly, only visible to
* unserialize (in practice unserialization handlers also see it). */
HT_ALLOW_COW_VIOLATION(h);
#endif
if (create_ref) {
/* Only create a reference if this is not from __unserialize(), because the existence of __unserialize can change */
struct igbinary_value_ref ref;
Expand Down
46 changes: 46 additions & 0 deletions tests/igbinary_097.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
Test serialize globals
--SKIPIF--
<?php
if (!extension_loaded("igbinary")) print "skip\n";
if (PHP_VERSION_ID >= 80100) print "skip php < 8.1\n"; // https://wiki.php.net/rfc/restrict_globals_usage
?>
--FILE--
<?php
call_user_func(function () {
foreach ($GLOBALS as $key => $_) {
if ($key !== 'GLOBALS') {
unset($GLOBALS[$key]);
}
}
$ser = igbinary_serialize($GLOBALS);
echo urlencode($ser) . "\n";
var_dump(igbinary_unserialize($ser));
$GLOBALS['globalVar'] = new stdClass();
$ser = igbinary_serialize($GLOBALS);
echo urlencode($ser) . "\n";
var_dump(igbinary_unserialize($ser));
});
--EXPECTF--
%00%00%00%02%14%01%11%07GLOBALS%14%01%0E%00%01%01
array(1) {
["GLOBALS"]=>
array(1) {
["GLOBALS"]=>
*RECURSION*
}
}
%00%00%00%02%14%02%11%07GLOBALS%14%02%0E%00%01%01%11%09globalVar%17%08stdClass%14%00%0E%01%22%02
array(2) {
["GLOBALS"]=>
array(2) {
["GLOBALS"]=>
*RECURSION*
["globalVar"]=>
object(stdClass)#3 (0) {
}
}
["globalVar"]=>
object(stdClass)#3 (0) {
}
}