@@ -103,7 +103,7 @@ typedef struct {
103
103
int level ;
104
104
int toffset ;
105
105
int curtag ;
106
- uint32_t ctag_index ;
106
+ zend_long ctag_index ;
107
107
char * * ltags ;
108
108
int lastwasopen ;
109
109
int skipwhite ;
@@ -602,11 +602,11 @@ static zval *xml_get_ctag(xml_parser *parser)
602
602
zval * data = xml_get_separated_data (parser );
603
603
if (EXPECTED (data )) {
604
604
zval * zv = zend_hash_index_find (Z_ARRVAL_P (data ), parser -> ctag_index );
605
- if (!zv ) {
605
+ if (UNEXPECTED ( !zv ) ) {
606
606
return NULL ;
607
607
}
608
608
ZVAL_DEREF (zv );
609
- if (Z_TYPE_P (zv ) != IS_ARRAY ) {
609
+ if (UNEXPECTED ( Z_TYPE_P (zv ) != IS_ARRAY ) ) {
610
610
return NULL ;
611
611
}
612
612
SEPARATE_ARRAY (zv );
@@ -697,9 +697,11 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
697
697
zval * data = xml_get_separated_data (parser );
698
698
if (EXPECTED (data )) {
699
699
/* 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 ;
703
705
} else {
704
706
zval_ptr_dtor (& tag );
705
707
}
@@ -817,12 +819,13 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len)
817
819
if (parser -> lastwasopen ) {
818
820
zval * ctag = xml_get_ctag (parser );
819
821
if (UNEXPECTED (!ctag )) {
822
+ zend_string_release_ex (decoded_value , false);
820
823
return ;
821
824
}
822
825
823
826
zval * myval ;
824
827
/* 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 ) {
826
829
size_t newlen = Z_STRLEN_P (myval ) + ZSTR_LEN (decoded_value );
827
830
Z_STR_P (myval ) = zend_string_extend (Z_STR_P (myval ), newlen , 0 );
828
831
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)
841
844
842
845
zval * data = xml_get_separated_data (parser );
843
846
if (UNEXPECTED (!data )) {
847
+ zend_string_release_ex (decoded_value , false);
844
848
return ;
845
849
}
846
850
0 commit comments