Skip to content

Commit a6403b7

Browse files
Do not convert error-causing numeric strings ahead-of-time
1 parent f9dc354 commit a6403b7

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

ext/opcache/Optimizer/pass2.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ void zend_optimizer_pass2(zend_op_array *op_array)
4848
case ZEND_POW:
4949
if (ZEND_OP1_TYPE(opline) == IS_CONST) {
5050
if (Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING) {
51-
convert_scalar_to_number(&ZEND_OP1_LITERAL(opline));
51+
/* don't optimise if it should produce a runtime numeric string error */
52+
if (!is_numeric_string(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), NULL, NULL, 0)) {
53+
convert_scalar_to_number(&ZEND_OP1_LITERAL(opline));
54+
}
5255
}
5356
}
5457
/* break missing *intentionally* - the assign_op's may only optimize op2 */
@@ -63,7 +66,10 @@ void zend_optimizer_pass2(zend_op_array *op_array)
6366
}
6467
if (ZEND_OP2_TYPE(opline) == IS_CONST) {
6568
if (Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING) {
66-
convert_scalar_to_number(&ZEND_OP2_LITERAL(opline));
69+
/* don't optimise if it should produce a runtime numeric string error */
70+
if (!is_numeric_string(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), NULL, NULL, 0)) {
71+
convert_scalar_to_number(&ZEND_OP2_LITERAL(opline));
72+
}
6773
}
6874
}
6975
break;
@@ -73,7 +79,11 @@ void zend_optimizer_pass2(zend_op_array *op_array)
7379
case ZEND_SR:
7480
if (ZEND_OP1_TYPE(opline) == IS_CONST) {
7581
if (Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_LONG) {
76-
convert_to_long(&ZEND_OP1_LITERAL(opline));
82+
/* don't optimise if it should produce a runtime numeric string error */
83+
if (!(Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING
84+
&& !is_numeric_string(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), NULL, NULL, 0))) {
85+
convert_to_long(&ZEND_OP1_LITERAL(opline));
86+
}
7787
}
7888
}
7989
/* break missing *intentionally - the assign_op's may only optimize op2 */
@@ -86,7 +96,11 @@ void zend_optimizer_pass2(zend_op_array *op_array)
8696
}
8797
if (ZEND_OP2_TYPE(opline) == IS_CONST) {
8898
if (Z_TYPE(ZEND_OP2_LITERAL(opline)) != IS_LONG) {
89-
convert_to_long(&ZEND_OP2_LITERAL(opline));
99+
/* don't optimise if it should produce a runtime numeric string error */
100+
if (!(Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING
101+
&& !is_numeric_string(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), NULL, NULL, 0))) {
102+
convert_to_long(&ZEND_OP2_LITERAL(opline));
103+
}
90104
}
91105
}
92106
break;

0 commit comments

Comments
 (0)