Skip to content

Commit c3376bf

Browse files
committed
Fix use-after-free due to packed->mixed conversion with __unserialize()
1 parent 0d3da6a commit c3376bf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
No packed -> mixed reallocation while populating __unserialize() array
3+
--FILE--
4+
<?php
5+
6+
$payload = 'O:13:"ArrayIterator":2:{i:0;i:0;s:1:"x";R:2;}';
7+
try {
8+
var_dump(unserialize($payload));
9+
} catch (Exception $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
13+
?>
14+
--EXPECT--
15+
Incomplete or ill-typed serialization data

ext/standard/var_unserializer.re

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ static inline int object_common(UNSERIALIZE_PARAMETER, zend_long elements, zend_
651651
}
652652

653653
array_init_size(&ary, elements);
654+
/* Avoid reallocation due to packed -> mixed conversion. */
655+
zend_hash_real_init_mixed(Z_ARRVAL(ary));
654656
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL(ary), elements, NULL)) {
655657
ZVAL_DEREF(rval);
656658
GC_ADD_FLAGS(Z_OBJ_P(rval), IS_OBJ_DESTRUCTOR_CALLED);

0 commit comments

Comments
 (0)