Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ function pg_socket_poll($socket, int $read, int $write, int $timeout = -1): int
function pg_set_chunked_rows_size(PgSql\Connection $connection, int $size): bool {}
#endif
#ifdef HAVE_PG_CLOSE_STMT
function pg_close_stmt(Pgsql\Connection $connection, string $statement_name): Pgsql\Result|false {}
function pg_close_stmt(Pgsql\Connection $connection, string $statement_name): PgSql\Result|false {}
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions ext/pgsql/pgsql_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 43 additions & 43 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,15 @@ static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size)
static HashTable* spl_fixedarray_object_get_gc(zend_object *obj, zval **table, int *n)
{
spl_fixedarray_object *intern = spl_fixed_array_from_obj(obj);
HashTable *ht = zend_std_get_properties(obj);

*table = intern->array.elements;
*n = (int)intern->array.size;

return ht;
if (obj->properties == NULL && obj->ce->default_properties_count == 0) {
return NULL;
} else {
return zend_std_get_properties(obj);
}
}

static HashTable* spl_fixedarray_object_get_properties_for(zend_object *obj, zend_prop_purpose purpose)
Expand Down Expand Up @@ -324,14 +327,14 @@ static zend_object *spl_fixedarray_object_clone(zend_object *old_object)
return new_object;
}

static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
static zend_never_inline zend_ulong spl_offset_convert_to_ulong_slow(const zval *offset) /* {{{ */
{
try_again:
switch (Z_TYPE_P(offset)) {
case IS_STRING: {
zend_ulong index;
if (ZEND_HANDLE_NUMERIC(Z_STR_P(offset), index)) {
return (zend_long) index;
return index;
}
break;
}
Expand All @@ -356,23 +359,35 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
return 0;
}

static zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset)
/* Returned index is an unsigned number such that we don't have to do a negative check.
* Negative numbers will be mapped at indices larger than ZEND_ULONG_MAX,
* which is beyond the maximum length. */
static zend_always_inline zend_ulong spl_offset_convert_to_ulong(const zval *offset)
{
zend_long index;
if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
/* Allow skipping exception check at call-site. */
ZEND_ASSERT(!EG(exception));
return Z_LVAL_P(offset);
} else {
return spl_offset_convert_to_ulong_slow(offset);
}
}

static zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset)
{
/* we have to return NULL on error here to avoid memleak because of
* ZE duplicating uninitialized_zval_ptr */
if (!offset) {
zend_throw_error(NULL, "[] operator not supported for SplFixedArray");
return NULL;
}

index = spl_offset_convert_to_long(offset);
if (EG(exception)) {
zend_ulong index = spl_offset_convert_to_ulong(offset);
if (UNEXPECTED(EG(exception))) {
return NULL;
}

if (index < 0 || index >= intern->array.size) {
if (UNEXPECTED(index >= intern->array.size)) {
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
return NULL;
} else {
Expand Down Expand Up @@ -407,22 +422,19 @@ static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *off

static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *intern, zval *offset, zval *value)
{
zend_long index;

if (!offset) {
/* '$array[] = value' syntax is not supported */
zend_throw_error(NULL, "[] operator not supported for SplFixedArray");
return;
}

index = spl_offset_convert_to_long(offset);
if (EG(exception)) {
zend_ulong index = spl_offset_convert_to_ulong(offset);
if (UNEXPECTED(EG(exception))) {
return;
}

if (index < 0 || index >= intern->array.size) {
if (UNEXPECTED(index >= intern->array.size)) {
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
return;
} else {
/* Fix #81429 */
zval *ptr = &(intern->array.elements[index]);
Expand Down Expand Up @@ -452,16 +464,13 @@ static void spl_fixedarray_object_write_dimension(zend_object *object, zval *off

static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *intern, zval *offset)
{
zend_long index;

index = spl_offset_convert_to_long(offset);
if (EG(exception)) {
zend_ulong index = spl_offset_convert_to_ulong(offset);
if (UNEXPECTED(EG(exception))) {
return;
}

if (index < 0 || index >= intern->array.size) {
if (UNEXPECTED(index >= intern->array.size)) {
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
return;
} else {
zval garbage;
ZVAL_COPY_VALUE(&garbage, &intern->array.elements[index]);
Expand All @@ -483,14 +492,12 @@ static void spl_fixedarray_object_unset_dimension(zend_object *object, zval *off

static bool spl_fixedarray_object_has_dimension_helper(spl_fixedarray_object *intern, zval *offset, bool check_empty)
{
zend_long index;

index = spl_offset_convert_to_long(offset);
if (EG(exception)) {
zend_ulong index = spl_offset_convert_to_ulong(offset);
if (UNEXPECTED(EG(exception))) {
return false;
}

if (index < 0 || index >= intern->array.size) {
if (index >= intern->array.size) {
return false;
}

Expand Down Expand Up @@ -691,11 +698,16 @@ PHP_METHOD(SplFixedArray, toArray)
intern = Z_SPLFIXEDARRAY_P(ZEND_THIS);

if (!spl_fixedarray_empty(&intern->array)) {
array_init(return_value);
for (zend_long i = 0; i < intern->array.size; i++) {
zend_hash_index_update(Z_ARRVAL_P(return_value), i, &intern->array.elements[i]);
Z_TRY_ADDREF(intern->array.elements[i]);
}
array_init_size(return_value, intern->array.size);
HashTable *ht = Z_ARRVAL_P(return_value);
zend_hash_real_init_packed(ht);

ZEND_HASH_FILL_PACKED(ht) {
for (zend_long i = 0; i < intern->array.size; i++) {
ZEND_HASH_FILL_ADD(&intern->array.elements[i]);
Z_TRY_ADDREF(intern->array.elements[i]);
}
} ZEND_HASH_FILL_END();
} else {
RETURN_EMPTY_ARRAY();
}
Expand Down Expand Up @@ -872,18 +884,6 @@ PHP_METHOD(SplFixedArray, getIterator)
zend_create_internal_iterator_zval(return_value, ZEND_THIS);
}

PHP_METHOD(SplFixedArray, jsonSerialize)
{
ZEND_PARSE_PARAMETERS_NONE();

spl_fixedarray_object *intern = Z_SPLFIXEDARRAY_P(ZEND_THIS);
array_init_size(return_value, intern->array.size);
for (zend_long i = 0; i < intern->array.size; i++) {
zend_hash_next_index_insert_new(Z_ARR_P(return_value), &intern->array.elements[i]);
Z_TRY_ADDREF(intern->array.elements[i]);
}
}

static void spl_fixedarray_it_dtor(zend_object_iterator *iter)
{
zval_ptr_dtor(&iter->data);
Expand Down
3 changes: 3 additions & 0 deletions ext/spl/spl_fixedarray.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ public function offsetUnset($index): void {}

public function getIterator(): Iterator {}

/**
* @implementation-alias SplFixedArray::toArray
*/
public function jsonSerialize(): array {}
}
5 changes: 2 additions & 3 deletions ext/spl/spl_fixedarray_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,10 +1273,10 @@ PHP_FUNCTION(str_increment)
ZSTR_VAL(tmp)[0] = ZSTR_VAL(incremented)[0];
break;
}
zend_string_release_ex(incremented, /* persistent */ false);
RETURN_STR(tmp);
zend_string_efree(incremented);
RETURN_NEW_STR(tmp);
}
RETURN_STR(incremented);
RETURN_NEW_STR(incremented);
}


Expand Down Expand Up @@ -1323,17 +1323,17 @@ PHP_FUNCTION(str_decrement)

if (UNEXPECTED(carry || (ZSTR_VAL(decremented)[0] == '0' && ZSTR_LEN(decremented) > 1))) {
if (ZSTR_LEN(decremented) == 1) {
zend_string_release_ex(decremented, /* persistent */ false);
zend_string_efree(decremented);
zend_argument_value_error(1, "\"%s\" is out of decrement range", ZSTR_VAL(str));
RETURN_THROWS();
}
zend_string *tmp = zend_string_alloc(ZSTR_LEN(decremented) - 1, 0);
memcpy(ZSTR_VAL(tmp), ZSTR_VAL(decremented) + 1, ZSTR_LEN(decremented) - 1);
ZSTR_VAL(tmp)[ZSTR_LEN(decremented) - 1] = '\0';
zend_string_release_ex(decremented, /* persistent */ false);
RETURN_STR(tmp);
zend_string_efree(decremented);
RETURN_NEW_STR(tmp);
}
RETURN_STR(decremented);
RETURN_NEW_STR(decremented);
}

#if defined(PHP_WIN32)
Expand Down
Loading