@@ -103,7 +103,7 @@ typedef struct {
103103 int level ;
104104 int toffset ;
105105 int curtag ;
106- uint32_t ctag_index ;
106+ zend_long ctag_index ;
107107 char * * ltags ;
108108 int lastwasopen ;
109109 int skipwhite ;
@@ -602,11 +602,11 @@ static zval *xml_get_ctag(xml_parser *parser)
602602 zval * data = xml_get_separated_data (parser );
603603 if (EXPECTED (data )) {
604604 zval * zv = zend_hash_index_find (Z_ARRVAL_P (data ), parser -> ctag_index );
605- if (!zv ) {
605+ if (UNEXPECTED ( !zv ) ) {
606606 return NULL ;
607607 }
608608 ZVAL_DEREF (zv );
609- if (Z_TYPE_P (zv ) != IS_ARRAY ) {
609+ if (UNEXPECTED ( Z_TYPE_P (zv ) != IS_ARRAY ) ) {
610610 return NULL ;
611611 }
612612 SEPARATE_ARRAY (zv );
@@ -697,9 +697,11 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
697697 zval * data = xml_get_separated_data (parser );
698698 if (EXPECTED (data )) {
699699 /* Note: due to array resizes or user interference,
700- * we have to store an index instaed of a zval into the array's memory. */
701- parser -> ctag_index = Z_ARRVAL_P (data )-> nNextFreeElement ;
702- zend_hash_next_index_insert (Z_ARRVAL_P (data ), & tag );
700+ * we have to store an index instead of a zval into the array's memory. */
701+ if (!zend_hash_next_index_insert (Z_ARRVAL_P (data ), & tag )) {
702+ zval_ptr_dtor (& tag );
703+ }
704+ parser -> ctag_index = Z_ARRVAL_P (data )-> nNextFreeElement - 1 ;
703705 } else {
704706 zval_ptr_dtor (& tag );
705707 }
@@ -817,12 +819,13 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
817819 if (parser -> lastwasopen ) {
818820 zval * ctag = xml_get_ctag (parser );
819821 if (UNEXPECTED (!ctag )) {
822+ zend_string_release_ex (decoded_value , false);
820823 return ;
821824 }
822825
823826 zval * myval ;
824827 /* check if the current tag already has a value - if yes append to that! */
825- if ((myval = zend_hash_find (Z_ARRVAL_P (ctag ), ZSTR_KNOWN (ZEND_STR_VALUE )))) {
828+ if ((myval = zend_hash_find (Z_ARRVAL_P (ctag ), ZSTR_KNOWN (ZEND_STR_VALUE ))) && Z_TYPE_P ( myval ) == IS_STRING ) {
826829 size_t newlen = Z_STRLEN_P (myval ) + ZSTR_LEN (decoded_value );
827830 Z_STR_P (myval ) = zend_string_extend (Z_STR_P (myval ), newlen , 0 );
828831 strncpy (Z_STRVAL_P (myval ) + Z_STRLEN_P (myval ) - ZSTR_LEN (decoded_value ),
@@ -841,6 +844,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
841844
842845 zval * data = xml_get_separated_data (parser );
843846 if (UNEXPECTED (!data )) {
847+ zend_string_release_ex (decoded_value , false);
844848 return ;
845849 }
846850
0 commit comments