Skip to content

Commit b03993d

Browse files
committed
Fix bug #67492: unserialize() SPL ArrayObject / SPLObjectStorage Type Confusion
1 parent f48b8f3 commit b03993d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

ext/spl/spl_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ SPL_METHOD(Array, unserialize)
18041804
++p;
18051805

18061806
ALLOC_INIT_ZVAL(pmembers);
1807-
if (!php_var_unserialize(&pmembers, &p, s + buf_len, &var_hash TSRMLS_CC)) {
1807+
if (!php_var_unserialize(&pmembers, &p, s + buf_len, &var_hash TSRMLS_CC) || Z_TYPE_P(pmembers) != IS_ARRAY) {
18081808
zval_ptr_dtor(&pmembers);
18091809
goto outexcept;
18101810
}

ext/spl/spl_observer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ SPL_METHOD(SplObjectStorage, unserialize)
914914
++p;
915915

916916
ALLOC_INIT_ZVAL(pmembers);
917-
if (!php_var_unserialize(&pmembers, &p, s + buf_len, &var_hash TSRMLS_CC)) {
917+
if (!php_var_unserialize(&pmembers, &p, s + buf_len, &var_hash TSRMLS_CC) || Z_TYPE_P(pmembers) != IS_ARRAY) {
918918
zval_ptr_dtor(&pmembers);
919919
goto outexcept;
920920
}

ext/spl/tests/SplObjectStorage_unserialize_bad.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $badblobs = array(
77
'x:i:2;i:0;,i:1;;i:0;,i:2;;m:a:0:{}',
88
'x:i:3;O:8:"stdClass":0:{},O:8:"stdClass":0:{};R:2;,i:1;;O:8:"stdClass":0:{},r:2;;m:a:0:{}',
99
'x:i:3;O:8:"stdClass":0:{},O:8:"stdClass":0:{};r:2;,i:1;;O:8:"stdClass":0:{},r:2;;m:a:0:{}',
10+
'x:i:1;O:8:"stdClass":0:{},N;;m:s:40:"1234567890123456789012345678901234567890"',
1011
);
1112
foreach($badblobs as $blob) {
1213
try {
@@ -17,6 +18,7 @@ try {
1718
echo $e->getMessage()."\n";
1819
}
1920
}
21+
echo "DONE\n";
2022
--EXPECTF--
2123
Error at offset 6 of 34 bytes
2224
Error at offset 46 of 89 bytes
@@ -42,4 +44,5 @@ object(SplObjectStorage)#2 (1) {
4244
}
4345
}
4446
}
45-
47+
Error at offset 79 of 78 bytes
48+
DONE

0 commit comments

Comments
 (0)