@@ -1850,6 +1850,14 @@ SPL_METHOD(Array, __serialize)
18501850 ZVAL_ARR (& tmp , zend_std_get_properties (& intern -> std ));
18511851 Z_TRY_ADDREF (tmp );
18521852 zend_hash_next_index_insert (Z_ARRVAL_P (return_value ), & tmp );
1853+
1854+ /* iterator class */
1855+ if (intern -> ce_get_iterator == spl_ce_ArrayIterator ) {
1856+ ZVAL_NULL (& tmp );
1857+ } else {
1858+ ZVAL_STR_COPY (& tmp , intern -> ce_get_iterator -> name );
1859+ }
1860+ zend_hash_next_index_insert (Z_ARRVAL_P (return_value ), & tmp );
18531861}
18541862/* }}} */
18551863
@@ -1859,18 +1867,22 @@ SPL_METHOD(Array, __unserialize)
18591867{
18601868 spl_array_object * intern = Z_SPLARRAY_P (ZEND_THIS );
18611869 HashTable * data ;
1862- zval * flags_zv , * storage_zv , * members_zv ;
1870+ zval * flags_zv , * storage_zv , * members_zv , * iterator_class_zv ;
18631871 zend_long flags ;
18641872
18651873 if (zend_parse_parameters (ZEND_NUM_ARGS (), "h" , & data ) == FAILURE ) {
18661874 RETURN_THROWS ();
18671875 }
18681876
1869- flags_zv = zend_hash_index_find (data , 0 );
1870- storage_zv = zend_hash_index_find (data , 1 );
1871- members_zv = zend_hash_index_find (data , 2 );
1877+ flags_zv = zend_hash_index_find (data , 0 );
1878+ storage_zv = zend_hash_index_find (data , 1 );
1879+ members_zv = zend_hash_index_find (data , 2 );
1880+ iterator_class_zv = zend_hash_index_find (data , 3 );
1881+
18721882 if (!flags_zv || !storage_zv || !members_zv ||
1873- Z_TYPE_P (flags_zv ) != IS_LONG || Z_TYPE_P (members_zv ) != IS_ARRAY ) {
1883+ Z_TYPE_P (flags_zv ) != IS_LONG || Z_TYPE_P (members_zv ) != IS_ARRAY ||
1884+ (iterator_class_zv && (Z_TYPE_P (iterator_class_zv ) != IS_NULL &&
1885+ Z_TYPE_P (iterator_class_zv ) != IS_STRING ))) {
18741886 zend_throw_exception (spl_ce_UnexpectedValueException ,
18751887 "Incomplete or ill-typed serialization data" , 0 );
18761888 RETURN_THROWS ();
@@ -1888,6 +1900,26 @@ SPL_METHOD(Array, __unserialize)
18881900 }
18891901
18901902 object_properties_load (& intern -> std , Z_ARRVAL_P (members_zv ));
1903+
1904+ if (iterator_class_zv && Z_TYPE_P (iterator_class_zv ) == IS_STRING ) {
1905+ zend_class_entry * ce = zend_lookup_class (Z_STR_P (iterator_class_zv ));
1906+
1907+ if (!ce ) {
1908+ zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
1909+ "Cannot deserialize ArrayObject with iterator class '%s'; no such class exists" ,
1910+ ZSTR_VAL (Z_STR_P (iterator_class_zv )));
1911+ RETURN_THROWS ();
1912+ }
1913+
1914+ if (!instanceof_function (ce , spl_ce_Iterator )) {
1915+ zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
1916+ "Cannot deserialize ArrayObject with iterator class '%s'; this class does not implement the Iterator interface" ,
1917+ ZSTR_VAL (Z_STR_P (iterator_class_zv )));
1918+ RETURN_THROWS ();
1919+ }
1920+
1921+ intern -> ce_get_iterator = ce ;
1922+ }
18911923}
18921924/* }}} */
18931925
0 commit comments