@@ -1840,6 +1840,14 @@ SPL_METHOD(Array, __serialize)
1840
1840
ZVAL_ARR (& tmp , zend_std_get_properties (ZEND_THIS ));
1841
1841
Z_TRY_ADDREF (tmp );
1842
1842
zend_hash_next_index_insert (Z_ARRVAL_P (return_value ), & tmp );
1843
+
1844
+ /* iterator class */
1845
+ if (intern -> ce_get_iterator == spl_ce_ArrayIterator ) {
1846
+ ZVAL_NULL (& tmp );
1847
+ } else {
1848
+ ZVAL_STR_COPY (& tmp , intern -> ce_get_iterator -> name );
1849
+ }
1850
+ zend_hash_next_index_insert (Z_ARRVAL_P (return_value ), & tmp );
1843
1851
}
1844
1852
/* }}} */
1845
1853
@@ -1849,18 +1857,22 @@ SPL_METHOD(Array, __unserialize)
1849
1857
{
1850
1858
spl_array_object * intern = Z_SPLARRAY_P (ZEND_THIS );
1851
1859
HashTable * data ;
1852
- zval * flags_zv , * storage_zv , * members_zv ;
1860
+ zval * flags_zv , * storage_zv , * members_zv , * iterator_class_zv ;
1853
1861
zend_long flags ;
1854
1862
1855
1863
if (zend_parse_parameters_throw (ZEND_NUM_ARGS (), "h" , & data ) == FAILURE ) {
1856
1864
return ;
1857
1865
}
1858
1866
1859
- flags_zv = zend_hash_index_find (data , 0 );
1860
- storage_zv = zend_hash_index_find (data , 1 );
1861
- members_zv = zend_hash_index_find (data , 2 );
1867
+ flags_zv = zend_hash_index_find (data , 0 );
1868
+ storage_zv = zend_hash_index_find (data , 1 );
1869
+ members_zv = zend_hash_index_find (data , 2 );
1870
+ iterator_class_zv = zend_hash_index_find (data , 3 );
1871
+
1862
1872
if (!flags_zv || !storage_zv || !members_zv ||
1863
- Z_TYPE_P (flags_zv ) != IS_LONG || Z_TYPE_P (members_zv ) != IS_ARRAY ) {
1873
+ Z_TYPE_P (flags_zv ) != IS_LONG || Z_TYPE_P (members_zv ) != IS_ARRAY ||
1874
+ (iterator_class_zv && (Z_TYPE_P (iterator_class_zv ) != IS_NULL &&
1875
+ Z_TYPE_P (iterator_class_zv ) != IS_STRING ))) {
1864
1876
zend_throw_exception (spl_ce_UnexpectedValueException ,
1865
1877
"Incomplete or ill-typed serialization data" , 0 );
1866
1878
return ;
@@ -1878,6 +1890,24 @@ SPL_METHOD(Array, __unserialize)
1878
1890
}
1879
1891
1880
1892
object_properties_load (& intern -> std , Z_ARRVAL_P (members_zv ));
1893
+
1894
+ if (iterator_class_zv && Z_TYPE_P (iterator_class_zv ) == IS_STRING ) {
1895
+ zend_class_entry * ce = zend_lookup_class (Z_STR_P (iterator_class_zv ));
1896
+
1897
+ if (!ce ) {
1898
+ zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
1899
+ "Cannot deserialize ArrayObject with iterator class '%s'; no such class exists" ,
1900
+ ZSTR_VAL (Z_STR_P (iterator_class_zv )));
1901
+ return ;
1902
+ } else if (!instanceof_function (ce , spl_ce_Iterator )) {
1903
+ zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
1904
+ "Cannot deserialize ArrayObject with iterator class '%s'; this class does not implement the Iterator interface" ,
1905
+ ZSTR_VAL (Z_STR_P (iterator_class_zv )));
1906
+ return ;
1907
+ } else {
1908
+ intern -> ce_get_iterator = ce ;
1909
+ }
1910
+ }
1881
1911
}
1882
1912
/* }}} */
1883
1913
0 commit comments