Skip to content

Commit 90b6b31

Browse files
committed
break recursion immediately on PHP <= 7.2 as well
1 parent 42e907c commit 90b6b31

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

tests/array_recursive.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test V8::executeString() : export of recursive array
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$a = [];
9+
$a[] = &$a;
10+
$a[] = 23;
11+
12+
$v8 = new V8Js();
13+
$v8->foo = $a;
14+
$v8->executeString('var_dump(PHP.foo);');
15+
16+
?>
17+
===EOF===
18+
--EXPECT--
19+
array(2) {
20+
[0] =>
21+
NULL
22+
[1] =>
23+
int(23)
24+
}
25+
===EOF===

v8js_convert.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ static v8::Local<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate
7171

7272
/* Prevent recursion */
7373
#if PHP_VERSION_ID >= 70300
74-
if (myht && GC_IS_RECURSIVE(myht)) {
74+
if (myht && GC_IS_RECURSIVE(myht))
7575
#else
76-
if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 1) {
76+
if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 0)
7777
#endif
78+
{
7879
return V8JS_NULL;
7980
}
8081

@@ -86,10 +87,11 @@ static v8::Local<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate
8687
ulong index = 0;
8788

8889
#if PHP_VERSION_ID >= 70300
89-
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
90+
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE))
9091
#else
91-
if (myht) {
92+
if (myht)
9293
#endif
94+
{
9395
GC_PROTECT_RECURSION(myht);
9496
}
9597

@@ -98,10 +100,11 @@ static v8::Local<v8::Value> v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate
98100
} ZEND_HASH_FOREACH_END();
99101

100102
#if PHP_VERSION_ID >= 70300
101-
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
103+
if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE))
102104
#else
103-
if (myht) {
105+
if (myht)
104106
#endif
107+
{
105108
GC_UNPROTECT_RECURSION(myht);
106109
}
107110
}

0 commit comments

Comments
 (0)