diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 0c1dfaf5dd131..8eb8468edd385 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1257,6 +1257,7 @@ PHP_FUNCTION(zip_read) zr_rsrc->zf = zip_fopen_index(rsrc_int->za, rsrc_int->index_current, 0); if (zr_rsrc->zf) { + Z_ADDREF_P(zip_dp); rsrc_int->index_current++; RETURN_RES(zend_register_resource(zr_rsrc, le_zip_entry)); } else { diff --git a/ext/zip/tests/gh17139.phpt b/ext/zip/tests/gh17139.phpt new file mode 100644 index 0000000000000..da53c62002419 --- /dev/null +++ b/ext/zip/tests/gh17139.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-17139 - zip_entry_name() crash +--EXTENSIONS-- +zip +--FILE-- + +--EXPECTF-- +Deprecated: Function zip_open() is deprecated in %s on line %d + +Deprecated: Function zip_read() is deprecated in %s on line %d + +Deprecated: Function zip_entry_name() is deprecated in %s on line %d +string(3) "foo"