1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-17139: Fix zip_entry_name() crash on invalid entry

Don't increment the refcount, but latter remember the ID to check
afterwards whether the resource still exists.

Replaces GH-17142.
Closes GH-17439.
This commit is contained in:
Niels Dossche
2025-01-10 18:35:16 +01:00
parent e8fce295bc
commit d08a9e0010
4 changed files with 28 additions and 1 deletions

4
NEWS
View File

@@ -38,6 +38,10 @@ PHP NEWS
. Fixed bug GH-17330 (SNMP::setSecurity segfault on closed session).
(David Carlier)
- Zip:
. Fixed bug GH-17139 (Fix zip_entry_name() crash on invalid entry).
(nielsdos)
02 Jan 2025, PHP 8.3.16RC1
- Core:

View File

@@ -1255,6 +1255,7 @@ PHP_FUNCTION(zip_read)
RETURN_FALSE;
}
zr_rsrc->zip_rsrc_handle = Z_RES_P(zip_dp)->handle;
zr_rsrc->zf = zip_fopen_index(rsrc_int->za, rsrc_int->index_current, 0);
if (zr_rsrc->zf) {
rsrc_int->index_current++;
@@ -1371,7 +1372,7 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{
RETURN_THROWS();
}
if (!zr_rsrc->zf) {
if (!zr_rsrc->zf || !zend_hash_index_exists(&EG(regular_list), zr_rsrc->zip_rsrc_handle)) {
RETURN_FALSE;
}

View File

@@ -60,6 +60,9 @@ typedef zip_rsrc * zip_rsrc_ptr;
typedef struct _ze_zip_read_rsrc {
struct zip_file *zf;
struct zip_stat sb;
/* Used to check if the zip resource still exists,
* without holding a reference. This works because the IDs are unique. */
zend_long zip_rsrc_handle;
} zip_read_rsrc;
/* Extends zend object */

View File

@@ -0,0 +1,19 @@
--TEST--
GH-17139 - zip_entry_name() crash
--EXTENSIONS--
zip
--FILE--
<?php
$zip = zip_open(__DIR__."/test_procedural.zip");
if (!is_resource($zip)) die("Failure");
// no need to bother looping over, the entry name should point to a dangling address from the first iteration
$zip = zip_read($zip);
var_dump(zip_entry_name($zip));
?>
--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
bool(false)