Skip to content

Commit a46a422

Browse files
committed
fixes
1 parent add7323 commit a46a422

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

ext/xml/tests/gh17187_2.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class ImmutableParser {
1616
xml_set_element_handler($this->parser, function ($parser, $name, $attrs) {
1717
echo "open\n";
1818
var_dump($name, $attrs);
19-
$this->immutableData1 = 0xdeadbeef;
20-
$this->immutableData2 = 0xbeefdead;
19+
$this->immutableData1 = 0xdead;
20+
$this->immutableData2 = 0xbeef;
2121
}, function ($parser, $name) {
2222
echo "close\n";
2323
var_dump($name);
@@ -49,5 +49,5 @@ close
4949
string(5) "CHILD"
5050
close
5151
string(9) "CONTAINER"
52-
int(3735928559)
53-
int(3203391149)
52+
int(57005)
53+
int(48879)

ext/xml/xml.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)