Skip to content

Commit d308724

Browse files
committed
Merge remote-tracking branch 'origin/PHP-5.6' into str_size_and_int64_56_backport
* origin/PHP-5.6: updated NEWS updated NEWS Fixed bug #66084 simplexml_load_string() mangles empty node name cleanup NEWS NEWS NEWS Fix Bug #66736 fpassthru broken
2 parents 582bf28 + 12e222e commit d308724

File tree

6 files changed

+112
-3
lines changed

6 files changed

+112
-3
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
. Fixed bug #64330 (stream_socket_server() creates wrong Abstract Namespace
1010
UNIX sockets). (Mike)
1111
. Fixed bug #66182 (exit in stream filter produces segfault). (Mike)
12+
. Fixed bug #66736 (fpassthru broken). (Mike)
1213
. Fixed bug #66822 (Cannot use T_POW in const expression) (Tjerk)
1314

1415
- SPL:
@@ -106,6 +107,10 @@ PHP NEWS
106107
. New pg_flush() and pg_consume_input() functions added to manually complete
107108
non-blocking reads/writes to underlying connection sockets. (Daniel Lowrey)
108109

110+
- SimpleXML:
111+
. Fixed bug #66084 (simplexml_load_string() mangles empty node name)
112+
(Anatol)
113+
109114
- SQLite:
110115
. Updated the bundled libsqlite to the version 3.8.3.1 (Anatol)
111116

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
11291129
node = NULL;
11301130
} else if (sxe->iter.type != SXE_ITER_CHILD) {
11311131

1132-
if ( !node->children || !node->parent || node->children->next || node->children->children || node->parent->children == node->parent->last ) {
1132+
if ( !node->children || !node->parent || !node->next || node->children->next || node->children->children || node->parent->children == node->parent->last ) {
11331133
node = node->children;
11341134
} else {
11351135
iter_data = sxe->iter.data;

ext/simplexml/tests/bug66084_0.phpt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
Bug #66084 simplexml_load_string() mangles empty node name, var_dump variant
3+
--SKIPIF--
4+
<?php if (!extension_loaded("simplexml")) print "skip simplexml not available"; ?>
5+
--FILE--
6+
<?php
7+
echo var_dump(simplexml_load_string('<a><b/><c><x/></c></a>')), "\n";
8+
echo var_dump(simplexml_load_string('<a><b/><d/><c><x/></c></a>')), "\n";
9+
echo var_dump(simplexml_load_string('<a><b/><c><d/><x/></c></a>')), "\n";
10+
echo var_dump(simplexml_load_string('<a><b/><c><d><x/></d></c></a>')), "\n";
11+
?>
12+
--EXPECT--
13+
object(SimpleXMLElement)#1 (2) {
14+
["b"]=>
15+
object(SimpleXMLElement)#2 (0) {
16+
}
17+
["c"]=>
18+
object(SimpleXMLElement)#3 (1) {
19+
["x"]=>
20+
object(SimpleXMLElement)#4 (0) {
21+
}
22+
}
23+
}
24+
25+
object(SimpleXMLElement)#1 (3) {
26+
["b"]=>
27+
object(SimpleXMLElement)#3 (0) {
28+
}
29+
["d"]=>
30+
object(SimpleXMLElement)#2 (0) {
31+
}
32+
["c"]=>
33+
object(SimpleXMLElement)#4 (1) {
34+
["x"]=>
35+
object(SimpleXMLElement)#5 (0) {
36+
}
37+
}
38+
}
39+
40+
object(SimpleXMLElement)#1 (2) {
41+
["b"]=>
42+
object(SimpleXMLElement)#4 (0) {
43+
}
44+
["c"]=>
45+
object(SimpleXMLElement)#2 (2) {
46+
["d"]=>
47+
object(SimpleXMLElement)#3 (0) {
48+
}
49+
["x"]=>
50+
object(SimpleXMLElement)#5 (0) {
51+
}
52+
}
53+
}
54+
55+
object(SimpleXMLElement)#1 (2) {
56+
["b"]=>
57+
object(SimpleXMLElement)#2 (0) {
58+
}
59+
["c"]=>
60+
object(SimpleXMLElement)#4 (1) {
61+
["d"]=>
62+
object(SimpleXMLElement)#5 (1) {
63+
["x"]=>
64+
object(SimpleXMLElement)#3 (0) {
65+
}
66+
}
67+
}
68+
}

ext/simplexml/tests/bug66084_1.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #66084 simplexml_load_string() mangles empty node name, json variant
3+
--SKIPIF--
4+
<?php if (!extension_loaded("simplexml")) print "skip simplexml not available"; ?>
5+
<?php if (!extension_loaded("json")) print "skip json not available"; ?>
6+
--FILE--
7+
<?php
8+
echo json_encode(simplexml_load_string('<a><b/><c><x/></c></a>')), "\n";
9+
echo json_encode(simplexml_load_string('<a><b/><d/><c><x/></c></a>')), "\n";
10+
echo json_encode(simplexml_load_string('<a><b/><c><d/><x/></c></a>')), "\n";
11+
echo json_encode(simplexml_load_string('<a><b/><c><d><x/></d></c></a>')), "\n";
12+
?>
13+
--EXPECT--
14+
{"b":{},"c":{"x":{}}}
15+
{"b":{},"d":{},"c":{"x":{}}}
16+
{"b":{},"c":{"d":{},"x":{}}}
17+
{"b":{},"c":{"d":{"x":{}}}}

main/output.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ PHPAPI int php_output_get_status(TSRMLS_D)
234234
* Unbuffered write */
235235
PHPAPI php_size_t php_output_write_unbuffered(const char *str, php_size_t len TSRMLS_DC)
236236
{
237+
#if PHP_DEBUG
238+
if (len > UINT_MAX) {
239+
php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; "
240+
"output will be truncated %lu => %lu",
241+
(unsigned long) len, (unsigned long) (len % UINT_MAX));
242+
}
243+
#endif
237244
if (OG(flags) & PHP_OUTPUT_DISABLED) {
238245
return 0;
239246
}
@@ -248,6 +255,13 @@ PHPAPI php_size_t php_output_write_unbuffered(const char *str, php_size_t len TS
248255
* Buffered write */
249256
PHPAPI php_size_t php_output_write(const char *str, php_size_t len TSRMLS_DC)
250257
{
258+
#if PHP_DEBUG
259+
if (len > UINT_MAX) {
260+
php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; "
261+
"output will be truncated %lu => %lu",
262+
(unsigned long) len, (unsigned long) (len % UINT_MAX));
263+
}
264+
#endif
251265
if (OG(flags) & PHP_OUTPUT_DISABLED) {
252266
return 0;
253267
}

main/streams/streams.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,16 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC)
14001400
p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
14011401

14021402
if (p) {
1403-
PHPWRITE(p, mapped);
1403+
do {
1404+
/* output functions return int, so pass in int max */
1405+
if (0 < (b = PHPWRITE(p, MIN(mapped - bcount, INT_MAX)))) {
1406+
bcount += b;
1407+
}
1408+
} while (b > 0 && mapped > bcount);
14041409

14051410
php_stream_mmap_unmap_ex(stream, mapped);
14061411

1407-
return mapped;
1412+
return bcount;
14081413
}
14091414
}
14101415

0 commit comments

Comments
 (0)