Skip to content
Open
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
8 changes: 4 additions & 4 deletions ext/spl/spl_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,10 @@ PHP_METHOD(SplHeap, __unserialize)
Z_PARAM_ARRAY_HT(data)
ZEND_PARSE_PARAMETERS_END();

if (UNEXPECTED(spl_heap_consistency_validations(intern, true) != SUCCESS)) {
RETURN_THROWS();
}

if (zend_hash_num_elements(data) != 2) {
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(intern->std.ce->name));
RETURN_THROWS();
Expand Down Expand Up @@ -1285,10 +1289,6 @@ PHP_METHOD(SplHeap, __unserialize)
RETURN_THROWS();
}

if (EG(exception)) {
RETURN_THROWS();
}

if (UNEXPECTED(spl_heap_consistency_validations(intern, false) != SUCCESS)) {
RETURN_THROWS();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
SplHeap should not accept unserialize data when it is corrupted or under modification
--FILE--
<?php

class MyHeap extends SplMaxHeap {
public function compare($a, $b): int {
global $array;
static $counter = 0;
if ($counter++ === 0)
$this->__unserialize($array);
return $a < $b ? -1 : ($a == $b ? 0 : 1);
}
}

$heap = new SplMaxHeap;
$heap->insert(1);
$array = $heap->__serialize();

$heap = new MyHeap;
$heap->insert(0);
try {
$heap->insert(2);
} catch (RuntimeException $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Heap cannot be changed when it is already being modified.