Skip to content

Commit 44ff983

Browse files
committed
Wrap all Exceptions thrown during unserialize() in UnserializationFailedException
1 parent 10406af commit 44ff983

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

ext/standard/var.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,10 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co
14131413
gc_check_possible_root(ref);
14141414
}
14151415

1416+
if (EG(exception)) {
1417+
zend_throw_exception_ex(php_var_ce_UnserializationFailedException, 0, "An Exception was thrown during unserialization");
1418+
}
1419+
14161420
cleanup:
14171421
if (class_hash) {
14181422
zend_hash_destroy(class_hash);

ext/standard/var_unserializer.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
279279
delayed_call_failed = 1;
280280
GC_ADD_FLAGS(Z_OBJ_P(zv), IS_OBJ_DESTRUCTOR_CALLED);
281281
}
282+
if (EG(exception)) {
283+
zend_throw_exception_ex(php_var_ce_UnserializationFailedException, 0, "An Exception was thrown in %s::__wakeup()", ZSTR_VAL(fci.object->ce->name));
284+
}
282285
BG(serialize_lock)--;
283286

284287
zval_ptr_dtor(&retval);
@@ -296,6 +299,7 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
296299
Z_OBJCE_P(zv)->__unserialize, Z_OBJ_P(zv), NULL, &param);
297300
if (EG(exception)) {
298301
delayed_call_failed = 1;
302+
zend_throw_exception_ex(php_var_ce_UnserializationFailedException, 0, "An Exception was thrown in %s::__unserialize()", ZSTR_VAL(Z_OBJ_P(zv)->ce->name));
299303
GC_ADD_FLAGS(Z_OBJ_P(zv), IS_OBJ_DESTRUCTOR_CALLED);
300304
}
301305
BG(serialize_lock)--;

0 commit comments

Comments
 (0)