diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 00713766fde60..613c3070e7a74 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -296,6 +296,8 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ php_ce_incomplete_class = register_class___PHP_Incomplete_Class(); php_register_incomplete_class_handlers(); + php_var_ce_UnserializationFailedException = register_class_UnserializationFailedException(zend_ce_exception); + assertion_error_ce = register_class_AssertionError(zend_ce_error); #ifdef ENABLE_TEST_CLASS diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 335974b44c609..3592352f42bc1 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -2849,6 +2849,13 @@ function memory_get_peak_usage(bool $real_usage = false): int {} function memory_reset_peak_usage(): void {} +/** + * @strict-properties + */ +class UnserializationFailedException extends \Exception +{ +} + /* versioning.c */ /** @compile-time-eval */ diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index a5b7b9a0dcff8..bddc5cdd7ae79 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: e46c8ef36dc0f29d877ae6e4096135414d0a4412 */ + * Stub hash: 1d2a0d8dee8dcf1d9956dbc9326ab0b4aeb2da51 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -3481,6 +3481,11 @@ static const zend_function_entry class_AssertionError_methods[] = { ZEND_FE_END }; + +static const zend_function_entry class_UnserializationFailedException_methods[] = { + ZEND_FE_END +}; + static void register_basic_functions_symbols(int module_number) { REGISTER_LONG_CONSTANT("EXTR_OVERWRITE", PHP_EXTR_OVERWRITE, CONST_PERSISTENT); @@ -3746,3 +3751,14 @@ static zend_class_entry *register_class_AssertionError(zend_class_entry *class_e return class_entry; } + +static zend_class_entry *register_class_UnserializationFailedException(zend_class_entry *class_entry_Exception) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "UnserializationFailedException", class_UnserializationFailedException_methods); + class_entry = zend_register_internal_class_ex(&ce, class_entry_Exception); + class_entry->ce_flags |= ZEND_ACC_NO_DYNAMIC_PROPERTIES; + + return class_entry; +} diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h index b816da8e19de9..7ce3fe951d573 100644 --- a/ext/standard/php_var.h +++ b/ext/standard/php_var.h @@ -22,6 +22,8 @@ PHP_MINIT_FUNCTION(var); +extern PHPAPI zend_class_entry *php_var_ce_UnserializationFailedException; + PHPAPI void php_var_dump(zval *struc, int level); PHPAPI void php_var_export(zval *struc, int level); PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf); diff --git a/ext/standard/var.c b/ext/standard/var.c index 268c535a80242..1507e7120fad5 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -35,6 +35,8 @@ struct php_serialize_data { uint32_t n; }; +PHPAPI zend_class_entry *php_var_ce_UnserializationFailedException; + #define COMMON (is_ref ? "&" : "") static void php_array_element_dump(zval *zv, zend_ulong index, zend_string *key, int level) /* {{{ */ @@ -1399,7 +1401,7 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co } if (!php_var_unserialize(retval, &p, p + buf_len, &var_hash)) { if (!EG(exception)) { - php_error_docref(NULL, E_NOTICE, "Error at offset " ZEND_LONG_FMT " of %zd bytes", + php_error_docref(NULL, E_WARNING, "Error at offset " ZEND_LONG_FMT " of %zd bytes", (zend_long)((char*)p - buf), buf_len); } if (BG(unserialize).level <= 1) { @@ -1413,6 +1415,10 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co gc_check_possible_root(ref); } + if (EG(exception)) { + zend_throw_exception_ex(php_var_ce_UnserializationFailedException, 0, "An Exception was thrown during unserialization"); + } + cleanup: if (class_hash) { zend_hash_destroy(class_hash); diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re index bcf19002fc0a2..51843ae97a151 100644 --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@ -279,6 +279,9 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) delayed_call_failed = 1; GC_ADD_FLAGS(Z_OBJ_P(zv), IS_OBJ_DESTRUCTOR_CALLED); } + if (EG(exception)) { + zend_throw_exception_ex(php_var_ce_UnserializationFailedException, 0, "An Exception was thrown in %s::__wakeup()", ZSTR_VAL(fci.object->ce->name)); + } BG(serialize_lock)--; zval_ptr_dtor(&retval); @@ -296,6 +299,7 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) Z_OBJCE_P(zv)->__unserialize, Z_OBJ_P(zv), NULL, ¶m); if (EG(exception)) { delayed_call_failed = 1; + zend_throw_exception_ex(php_var_ce_UnserializationFailedException, 0, "An Exception was thrown in %s::__unserialize()", ZSTR_VAL(Z_OBJ_P(zv)->ce->name)); GC_ADD_FLAGS(Z_OBJ_P(zv), IS_OBJ_DESTRUCTOR_CALLED); } BG(serialize_lock)--;