-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from TysonAndre/strict_hash-change
Fix handling of reference cycles in Teds\strict_hash
- Loading branch information
Showing
8 changed files
with
327 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,20 +10,22 @@ | |
<email>[email protected]</email> | ||
<active>yes</active> | ||
</lead> | ||
<date>2022-10-10</date> | ||
<date>2022-10-22</date> | ||
<time>16:00:00</time> | ||
<version> | ||
<release>1.2.6</release> | ||
<api>1.2.6</api> | ||
<release>1.2.7</release> | ||
<api>1.2.7</api> | ||
</version> | ||
<stability> | ||
<release>stable</release> | ||
<api>stable</api> | ||
</stability> | ||
<license uri="https://github.com/TysonAndre/teds/blob/main/COPYING">BSD-3-Clause</license> | ||
<notes> | ||
* Fix a build warning in clang for placeholders indicating that a data structure was constructed/unserialized. | ||
* Fix a build warning after change to expected return type of `count_elements` object handler implementation. | ||
* Fix an edge case in Teds\strict_hash for different arrays with reference cycles | ||
where php's strict equality operator would return true: '==='. | ||
(and for Teds\unique_values, Teds\StrictHashSet, and Teds\StrictHashMap) | ||
'$x === $y' should now always imply that 'Teds\strict_hash($x) === Teds\strict_hash($y)' | ||
</notes> | ||
<contents> | ||
<dir name="/"> | ||
|
@@ -383,6 +385,8 @@ | |
<file name="misc/strict_hash_array_recursion_32bit.phpt" role="test" /> | ||
<file name="misc/strict_hash_array_references.phpt" role="test" /> | ||
<file name="misc/strict_hash_array_references_32bit.phpt" role="test" /> | ||
<file name="misc/strict_hash_cyclic_recursion_fallback.phpt" role="test" /> | ||
<file name="misc/strict_hash_cyclic_recursion_fallback_32bit.phpt" role="test" /> | ||
<file name="misc/strict_hash_recursion.phpt" role="test" /> | ||
<file name="misc/strict_hash_recursion_32bit.phpt" role="test" /> | ||
<file name="misc/strict_hash_typed_property.phpt" role="test" /> | ||
|
@@ -404,6 +408,23 @@ | |
<providesextension>teds</providesextension> | ||
<extsrcrelease /> | ||
<changelog> | ||
<release> | ||
<date>2022-10-10</date> | ||
<time>16:00:00</time> | ||
<version> | ||
<release>1.2.6</release> | ||
<api>1.2.6</api> | ||
</version> | ||
<stability> | ||
<release>stable</release> | ||
<api>stable</api> | ||
</stability> | ||
<license uri="https://github.com/TysonAndre/teds/blob/main/COPYING">BSD-3-Clause</license> | ||
<notes> | ||
* Fix a build warning in clang for placeholders indicating that a data structure was constructed/unserialized. | ||
* Fix a build warning after change to expected return type of `count_elements` object handler implementation. | ||
</notes> | ||
</release> | ||
<release> | ||
<date>2022-10-10</date> | ||
<time>16:00:00</time> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--TEST-- | ||
Test strict_hash() handling of cyclic recursion edge cases | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE < 8) echo "skip 64-bit only\n"; ?> | ||
--FILE-- | ||
<?php | ||
|
||
$x = []; | ||
$x[1] = &$x; | ||
$y = [1 => $x]; | ||
|
||
var_dump($x === $y); // true, so we expect the strict_hash to be the same. Only hash the key 1 but don't hash the top level array | ||
|
||
// Expected: same hashes are computed | ||
// Observed: Different hashes in Teds 1.2.6 | ||
var_dump(Teds\strict_hash($x), Teds\strict_hash($y)); | ||
var_dump($x); | ||
echo "Test hash skips hashing sub-arrays if array contains cyclic arrays anywhere\n"; | ||
$x[2] = []; | ||
$x[1] = &$x; | ||
var_dump(Teds\strict_hash($x)); | ||
$x[2][] = 1; | ||
var_dump(Teds\strict_hash($x)); | ||
var_dump($x); | ||
$y[2] = [1]; | ||
$y[1] = &$x; | ||
echo "x, y values:\n"; | ||
var_dump($x); | ||
var_dump($y); | ||
echo "x === y: "; | ||
var_export($x === $y); | ||
echo "\n"; | ||
var_dump(Teds\strict_hash($x)); | ||
var_dump(Teds\strict_hash($y)); | ||
$other = []; | ||
$other[1] = &$other; | ||
var_dump(new Teds\StrictHashSet([$x, $y, null, &$other, $other, [1 => null]])); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
int(-5561530578556069188) | ||
int(-5561530578556069188) | ||
array(1) { | ||
[1]=> | ||
*RECURSION* | ||
} | ||
Test hash skips hashing sub-arrays if array contains cyclic arrays anywhere | ||
int(7251907892736144760) | ||
int(7251907892736144760) | ||
array(2) { | ||
[1]=> | ||
*RECURSION* | ||
[2]=> | ||
array(1) { | ||
[0]=> | ||
int(1) | ||
} | ||
} | ||
x, y values: | ||
array(2) { | ||
[1]=> | ||
*RECURSION* | ||
[2]=> | ||
array(1) { | ||
[0]=> | ||
int(1) | ||
} | ||
} | ||
array(2) { | ||
[1]=> | ||
&array(2) { | ||
[1]=> | ||
*RECURSION* | ||
[2]=> | ||
array(1) { | ||
[0]=> | ||
int(1) | ||
} | ||
} | ||
[2]=> | ||
array(1) { | ||
[0]=> | ||
int(1) | ||
} | ||
} | ||
x === y: true | ||
int(7251907892736144760) | ||
int(7251907892736144760) | ||
object(Teds\StrictHashSet)#1 (4) { | ||
[0]=> | ||
array(2) { | ||
[1]=> | ||
*RECURSION* | ||
[2]=> | ||
array(1) { | ||
[0]=> | ||
int(1) | ||
} | ||
} | ||
[1]=> | ||
NULL | ||
[2]=> | ||
array(1) { | ||
[1]=> | ||
*RECURSION* | ||
} | ||
[3]=> | ||
array(1) { | ||
[1]=> | ||
NULL | ||
} | ||
} |
Oops, something went wrong.