Skip to content

Commit 1f54ffb

Browse files
committed
Fix some concat issues
1 parent c76a25d commit 1f54ffb

File tree

5 files changed

+86
-15
lines changed

5 files changed

+86
-15
lines changed

Zend/zend_operators.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ ZEND_API zend_result ZEND_FASTCALL shift_right_function(zval *result, zval *op1,
18871887

18881888
ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /* {{{ */
18891889
{
1890-
zval *orig_op1 = op1;
1890+
zval *orig_op1 = op1;
18911891
zval op1_copy, op2_copy;
18921892

18931893
ZVAL_UNDEF(&op1_copy);
@@ -1955,6 +1955,11 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
19551955
size_t op2_len = Z_STRLEN_P(op2);
19561956
size_t result_len = op1_len + op2_len;
19571957
zend_string *result_str;
1958+
uint32_t flags = 0;
1959+
1960+
if (ZSTR_IS_VALID_UTF8(Z_STR_P(op1)) && ZSTR_IS_VALID_UTF8(Z_STR_P(op2))) {
1961+
flags = IS_STR_VALID_UTF8;
1962+
}
19581963

19591964
if (UNEXPECTED(op1_len > ZSTR_MAX_LEN - op2_len)) {
19601965
zend_throw_error(NULL, "String size overflow");
@@ -1976,6 +1981,7 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
19761981
i_zval_ptr_dtor(result);
19771982
}
19781983
}
1984+
GC_ADD_FLAGS(result_str, flags);
19791985

19801986
/* This has to happen first to account for the cases where result == op1 == op2 and
19811987
* the realloc is done. In this case this line will also update Z_STRVAL_P(op2) to
@@ -1984,9 +1990,6 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
19841990

19851991
memcpy(ZSTR_VAL(result_str) + op1_len, Z_STRVAL_P(op2), op2_len);
19861992
ZSTR_VAL(result_str)[result_len] = '\0';
1987-
if (ZSTR_IS_VALID_UTF8(Z_STR_P(op1)) && ZSTR_IS_VALID_UTF8(Z_STR_P(op2))) {
1988-
GC_ADD_FLAGS(result_str, IS_STR_VALID_UTF8);
1989-
}
19901993
}
19911994

19921995
zval_ptr_dtor_str(&op1_copy);

Zend/zend_vm_def.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3176,6 +3176,7 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(53, ZEND_FAST_CONCAT, CONST|TMPVAR|CV, CONST|TMP
31763176

31773177
str = zend_string_extend(op1_str, len + ZSTR_LEN(op2_str), 0);
31783178
memcpy(ZSTR_VAL(str) + len, ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
3179+
GC_ADD_FLAGS(str, flags);
31793180
ZVAL_NEW_STR(EX_VAR(opline->result.var), str);
31803181
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
31813182
zend_string_release_ex(op2_str, 0);
@@ -3184,6 +3185,7 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(53, ZEND_FAST_CONCAT, CONST|TMPVAR|CV, CONST|TMP
31843185
str = zend_string_alloc(ZSTR_LEN(op1_str) + ZSTR_LEN(op2_str), 0);
31853186
memcpy(ZSTR_VAL(str), ZSTR_VAL(op1_str), ZSTR_LEN(op1_str));
31863187
memcpy(ZSTR_VAL(str) + ZSTR_LEN(op1_str), ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
3188+
GC_ADD_FLAGS(str, flags);
31873189
ZVAL_NEW_STR(EX_VAR(opline->result.var), str);
31883190
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
31893191
zend_string_release_ex(op1_str, 0);
@@ -3192,7 +3194,6 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(53, ZEND_FAST_CONCAT, CONST|TMPVAR|CV, CONST|TMP
31923194
zend_string_release_ex(op2_str, 0);
31933195
}
31943196
}
3195-
GC_ADD_FLAGS(Z_STR_P(EX_VAR(opline->result.var)), flags);
31963197
ZEND_VM_NEXT_OPCODE();
31973198
}
31983199

Zend/zend_vm_execute.h

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,11 @@ static void ZEND_FASTCALL zend_jit_fast_assign_concat_helper(zval *op1, zval *op
16331633
size_t op2_len = Z_STRLEN_P(op2);
16341634
size_t result_len = op1_len + op2_len;
16351635
zend_string *result_str;
1636+
uint32_t flags = 0;
1637+
1638+
if (ZSTR_IS_VALID_UTF8(Z_STR_P(op1)) && ZSTR_IS_VALID_UTF8(Z_STR_P(op2))) {
1639+
flags = IS_STR_VALID_UTF8;
1640+
}
16361641

16371642
if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
16381643
zend_throw_error(NULL, "String size overflow");
@@ -1654,6 +1659,7 @@ static void ZEND_FASTCALL zend_jit_fast_assign_concat_helper(zval *op1, zval *op
16541659
}
16551660
result_str = zend_string_alloc(result_len, 0);
16561661
memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
1662+
GC_ADD_FLAGS(result_str, flags);
16571663
} while(0);
16581664

16591665
ZVAL_NEW_STR(op1, result_str);
@@ -1667,13 +1673,19 @@ static void ZEND_FASTCALL zend_jit_fast_concat_helper(zval *result, zval *op1, z
16671673
size_t op2_len = Z_STRLEN_P(op2);
16681674
size_t result_len = op1_len + op2_len;
16691675
zend_string *result_str;
1676+
uint32_t flags = 0;
1677+
1678+
if (ZSTR_IS_VALID_UTF8(Z_STR_P(op1)) && ZSTR_IS_VALID_UTF8(Z_STR_P(op2))) {
1679+
flags = IS_STR_VALID_UTF8;
1680+
}
16701681

16711682
if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
16721683
zend_throw_error(NULL, "String size overflow");
16731684
return;
16741685
}
16751686

16761687
result_str = zend_string_alloc(result_len, 0);
1688+
GC_ADD_FLAGS(result_str, flags);
16771689
memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
16781690

16791691
ZVAL_NEW_STR(result, result_str);
@@ -1689,6 +1701,11 @@ static void ZEND_FASTCALL zend_jit_fast_concat_tmp_helper(zval *result, zval *op
16891701
size_t op2_len = Z_STRLEN_P(op2);
16901702
size_t result_len = op1_len + op2_len;
16911703
zend_string *result_str;
1704+
uint32_t flags = 0;
1705+
1706+
if (ZSTR_IS_VALID_UTF8(Z_STR_P(op1)) && ZSTR_IS_VALID_UTF8(Z_STR_P(op2))) {
1707+
flags = IS_STR_VALID_UTF8;
1708+
}
16921709

16931710
if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
16941711
zend_throw_error(NULL, "String size overflow");
@@ -1707,6 +1724,7 @@ static void ZEND_FASTCALL zend_jit_fast_concat_tmp_helper(zval *result, zval *op
17071724
GC_DELREF(op1_str);
17081725
}
17091726
result_str = zend_string_alloc(result_len, 0);
1727+
GC_ADD_FLAGS(result_str, flags);
17101728
memcpy(ZSTR_VAL(result_str), ZSTR_VAL(op1_str), op1_len);
17111729
} while (0);
17121730

0 commit comments

Comments
 (0)