Skip to content

Commit 46a15ed

Browse files
committed
Fix crash in property existence test in ext/zip
When type == 2, the zval is not initialized, so zval_ptr_dtor() on it will crash. Unfortunately couldn't test with property_exists() or Reflection because they have fast paths that go through the property info, but fortunately there are paths that don't implement a fast path (e.g. because it doesn't make sense at that point), like with array_column(). So we use array_column() to trigger the crash. Closes GH-20496.
1 parent d2c5b3b commit 46a15ed

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ PHP NEWS
4242
. Fixed bug GH-20439 (xml_set_default_handler() does not properly handle
4343
special characters in attributes when passing data to callback). (ndossche)
4444

45+
- Zip:
46+
. Fix crash in property existence test. (ndossche)
47+
4548
20 Nov 2025, PHP 8.3.28
4649

4750
- Core:

ext/zip/php_zip.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,8 @@ static int php_zip_has_property(zend_object *object, zend_string *name, int type
977977
} else if (type == 0) {
978978
retval = (Z_TYPE(tmp) != IS_NULL);
979979
}
980+
zval_ptr_dtor(&tmp);
980981
}
981-
982-
zval_ptr_dtor(&tmp);
983982
} else {
984983
retval = zend_std_has_property(object, name, type, cache_slot);
985984
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Property existence test can cause a crash
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
8+
$archive = new ZipArchive(__DIR__.'/property_existence.zip');
9+
var_dump(array_column([$archive], 'lastId'));
10+
11+
?>
12+
--CLEAN--
13+
<?php
14+
@unlink(__DIR__.'/property_existence.zip');
15+
?>
16+
--EXPECT--
17+
array(1) {
18+
[0]=>
19+
int(-1)
20+
}

0 commit comments

Comments
 (0)