Skip to content

Commit dccd4af

Browse files
committed
ext/zip: Cancel operation if user callback throws an exception
1 parent 79b9fe3 commit dccd4af

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ext/zip/php_zip.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -3070,10 +3070,12 @@ static int php_zip_cancel_callback(zip_t *arch, void *ptr)
30703070
ze_zip_object *obj = ptr;
30713071

30723072
zend_call_known_fcc(&obj->cancel_callback, &cb_retval, 0, NULL, NULL);
3073-
if (!Z_ISUNDEF(cb_retval)) {
3074-
retval = zval_get_long(&cb_retval);
3075-
zval_ptr_dtor(&cb_retval);
3073+
if (Z_ISUNDEF(cb_retval)) {
3074+
/* Cancel if an exception has been thrown */
3075+
return -1;
30763076
}
3077+
retval = zval_get_long(&cb_retval);
3078+
zval_ptr_dtor(&cb_retval);
30773079

30783080
return retval;
30793081
}

ext/zip/tests/oo_cancel_trampoline.phpt

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ ValueError: Invalid or uninitialized Zip object
9191
bool(true)
9292
bool(true)
9393
Trampoline for trampolineThrow
94+
95+
Warning: ZipArchive::close(): Operation cancelled in %s on line %d
9496
Exception: boo
95-
bool(false)
96-
string(8) "No error"
97+
bool(true)
98+
string(19) "Operation cancelled"
9799
Done

0 commit comments

Comments
 (0)