Skip to content

Fix performance for Bcmath numbers with trailing zeros #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7124c53
Adjust bc_num to number without trailing zeros
jorgsowa Jul 6, 2023
0653132
Improve tests for bcpow with zero
jorgsowa Jul 7, 2023
ec994a3
Fixed tests for 32bits systems
jorgsowa Jul 8, 2023
f55eab1
Fixed test case for maximum exponent for int to lower than max
jorgsowa Jul 8, 2023
d63ba2f
Fix bcmath tests for number zero
jorgsowa Jul 8, 2023
d812639
Remove unused ZEND_STACK_GROWS_DOWNWARDS constant (#11762)
petk Jul 22, 2023
8fbbfd6
zend call stack fix freebsd code path. (#11766)
devnexen Jul 23, 2023
5d6d66b
zend vm savee registers support for riscv 64. (#11773)
devnexen Jul 24, 2023
c6202fc
Fixed incorrect QM_ASSIGN elimination
dstogov Jul 24, 2023
f8f3280
Use xmlSetNsProp when possible to prevent parsing the name
nielsdos Jul 22, 2023
1bd964c
Remove useless readonly checks
nielsdos Jul 22, 2023
a808b32
Simplify configuration getters (#11778)
nielsdos Jul 24, 2023
39d7258
Refactor BCMath bundledlib and extension (#10774)
Girgias Jul 24, 2023
acf1bf7
[skip ci] Add myself to CODEOWNER for BCMath extension
Girgias Jul 24, 2023
ac1fc0e
Fix DOMEntity field getter bugs
nielsdos Jul 23, 2023
6da01ce
Fix incorrect attribute existence check in DOMElement::setAttributeNo…
nielsdos Jul 23, 2023
058cfa5
Fix DOMCharacterData::replaceWith() with itself
nielsdos Jul 22, 2023
05b4555
Fix empty argument cases for DOMParentNode methods
nielsdos Jul 22, 2023
095be3e
[skip ci] Don't render zend_vm_handlers.h in PRs
iluuu1994 Jul 25, 2023
96b77f6
Fix open_basedir leak
iluuu1994 Jul 24, 2023
716f6b4
Call cast_object handler from get_properties_for
iluuu1994 Jun 30, 2023
2372bf2
CS
derickr Jul 19, 2023
7ecb398
Make the new DatePeriod::createFromISO8601String method emit DateTime…
derickr Jul 19, 2023
00163a3
Adjust bc_num to number without trailing zeros
jorgsowa Jul 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Collapse generated files within a pull request.
**/*_arginfo.h linguist-generated
/Zend/zend_vm_execute.h linguist-generated
/Zend/zend_vm_handlers.h linguist-generated
/Zend/zend_vm_opcodes.[ch] linguist-generated

# The OSS fuzz files are bunary
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.stub.php @kocsismate
/.github @iluuu1994 @TimWolla
/build/gen_stub.php @kocsismate
/ext/bcmath @Girgias
/ext/curl @adoy
/ext/date @derickr
/ext/dba @Girgias
Expand Down
10 changes: 10 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.3.0beta2

- DOM:
. Fix DOMEntity field getter bugs. (nielsdos)
. Fix incorrect attribute existence check in DOMElement::setAttributeNodeNS.
(nielsdos)
. Fix DOMCharacterData::replaceWith() with itself. (nielsdos)
. Fix empty argument cases for DOMParentNode methods. (nielsdos)

- Core:
. Fixed oss-fuzz #60741 (Leak in open_basedir). (ilutov)

- FFI:
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)

Expand Down
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ PHP 8.3 INTERNALS UPGRADE NOTES
* _php_stream_dirent now has an extra d_type field that is used to store the
directory entry type. This can be used to avoid additional stat calls for
types when the type is already known.
* zend_std_get_properties_for now calls the cast_object handler when casting
objects to arrays.

========================
2. Build system changes
Expand Down
12 changes: 8 additions & 4 deletions Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
&& opline->opcode != ZEND_MATCH
&& zend_optimizer_update_op1_const(op_array, opline, &c)) {
VAR_SOURCE(op1) = NULL;
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
if (!zend_bitset_in(used_ext, VAR_NUM(src->result.var))) {
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
}
++(*opt_count);
} else {
zval_ptr_dtor_nogc(&c);
Expand All @@ -197,8 +199,10 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
ZVAL_COPY(&c, &ZEND_OP1_LITERAL(src));
if (zend_optimizer_update_op2_const(op_array, opline, &c)) {
VAR_SOURCE(op2) = NULL;
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
if (!zend_bitset_in(used_ext, VAR_NUM(src->result.var))) {
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
}
++(*opt_count);
} else {
zval_ptr_dtor_nogc(&c);
Expand Down
4 changes: 3 additions & 1 deletion Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ int main(void) {
return f((uintptr_t)&local) ? 0 : 1;
}
]])], [
AC_DEFINE([ZEND_STACK_GROWS_DOWNWARDS], 1, [Define if the stack grows downwards])
AC_DEFINE([ZEND_CHECK_STACK_LIMIT], 1, [Define if checking the stack limit is supported])
AC_MSG_RESULT(yes)
], [
Expand Down Expand Up @@ -355,6 +354,9 @@ if test "$ZEND_GCC_GLOBAL_REGS" != "no"; then
#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__)
# define ZEND_VM_FP_GLOBAL_REG "x27"
# define ZEND_VM_IP_GLOBAL_REG "x28"
#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__riscv) && __riscv_xlen == 64
# define ZEND_VM_FP_GLOBAL_REG "x18"
# define ZEND_VM_IP_GLOBAL_REG "x19"
#else
# error "global register variables are not supported"
#endif
Expand Down
9 changes: 9 additions & 0 deletions Zend/tests/oss_fuzz_60741.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
oss-fuzz #60741: Leak in open_basedir
--INI--
open_basedir="{TMP}"
--FILE--
<?php
ini_set('open_basedir', ini_get('open_basedir'));
?>
--EXPECT--
18 changes: 0 additions & 18 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,29 +1271,11 @@ void zend_call_destructors(void) /* {{{ */
}
/* }}} */

static void zend_release_open_basedir(void)
{
/* Release custom open_basedir config, this needs to happen before ini shutdown */
if (PG(open_basedir)) {
zend_ini_entry *ini_entry = zend_hash_str_find_ptr(EG(ini_directives), "open_basedir", strlen("open_basedir"));
/* ini_entry->modified is unreliable, it might also be set when on_update has failed. */
if (ini_entry
&& ini_entry->modified
&& ini_entry->value != ini_entry->orig_value) {
efree(PG(open_basedir));
PG(open_basedir) = NULL;
}
}
}

ZEND_API void zend_deactivate(void) /* {{{ */
{
/* we're no longer executing anything */
EG(current_execute_data) = NULL;

/* Needs to run before zend_ini_deactivate(). */
zend_release_open_basedir();

zend_try {
shutdown_scanner();
} zend_end_try();
Expand Down
13 changes: 6 additions & 7 deletions Zend/zend_call_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static bool zend_call_stack_is_main_thread(void) {
# endif
}

# ifdef HAVE_PTHREAD_GETATTR_NP
# if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK)
static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack)
{
pthread_attr_t attr;
Expand Down Expand Up @@ -145,12 +145,12 @@ static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack)

return true;
}
# else /* HAVE_PTHREAD_GETATTR_NP */
# else /* defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */
static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack)
{
return false;
}
# endif /* HAVE_PTHREAD_GETATTR_NP */
# endif /* defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */

static bool zend_call_stack_get_linux_proc_maps(zend_call_stack *stack)
{
Expand Down Expand Up @@ -251,14 +251,13 @@ static bool zend_call_stack_is_main_thread(void)
return is_main == -1 || is_main == 1;
}

# if defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GET_STACK)
# if defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK)
static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack)
{
pthread_attr_t attr;
int error;
void *addr;
size_t max_size;
size_t guard_size;

/* pthread will return bogus values for the main thread */
ZEND_ASSERT(!zend_call_stack_is_main_thread());
Expand All @@ -285,12 +284,12 @@ static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack)
pthread_attr_destroy(&attr);
return false;
}
# else /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GET_STACK) */
# else /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */
static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack)
{
return false;
}
# endif /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GET_STACK) */
# endif /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */

static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack)
{
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
# elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__)
# define ZEND_VM_FP_GLOBAL_REG "x27"
# define ZEND_VM_IP_GLOBAL_REG "x28"
#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__riscv) && __riscv_xlen == 64
# define ZEND_VM_FP_GLOBAL_REG "x18"
# define ZEND_VM_IP_GLOBAL_REG "x19"
# endif
#endif

Expand Down
10 changes: 10 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,16 @@ ZEND_API HashTable *zend_std_get_properties_for(zend_object *obj, zend_prop_purp
}
ZEND_FALLTHROUGH;
case ZEND_PROP_PURPOSE_ARRAY_CAST:
if (obj->handlers->cast_object != std_object_handlers.cast_object) {
zval result;
if (obj->handlers->cast_object(obj, &result, IS_ARRAY) == SUCCESS) {
return Z_ARRVAL(result);
}
if (EG(exception)) {
return NULL;
}
}
ZEND_FALLTHROUGH;
case ZEND_PROP_PURPOSE_SERIALIZE:
case ZEND_PROP_PURPOSE_VAR_EXPORT:
case ZEND_PROP_PURPOSE_JSON:
Expand Down
Loading