Skip to content

Commit bc3a7c7

Browse files
authored
Fix phpGH-21705: ZipArchive::getFromIndex() ignores FL_UNCHANGED (php#21706)
ZipArchive::getFromIndex() already passed flags to zip_fopen_index(), but it used an unflagged stat call to determine the entry size. Use the same flags for the stat lookup so deleted entries can still be read with ZipArchive::FL_UNCHANGED, matching ZipArchive::getFromName(). Closes php#21706
1 parent b6938a2 commit bc3a7c7

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ PHP NEWS
6565
. Fixed bug GH-22395 (base_convert() outputs at most 64 characters).
6666
(Weilin Du)
6767

68+
- Zip:
69+
. Fixed bug GH-21705 (ZipArchive::getFromIndex() ignores
70+
ZipArchive::FL_UNCHANGED for deleted entries). (Weilin Du)
71+
6872
02 Jul 2026, PHP 8.4.23
6973

7074
- Core:

ext/zip/php_zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
29392939

29402940
ZIP_FROM_OBJECT(intern, self);
29412941

2942-
PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
2942+
PHP_ZIP_STAT_INDEX(intern, index, flags, sb);
29432943
}
29442944

29452945
if (sb.size < 1) {

ext/zip/tests/bug_gh21705.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
ZipArchive::getFromIndex() honors FL_UNCHANGED for deleted entries
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
$name = __DIR__ . '/bug_gh21705.zip';
8+
@unlink($name);
9+
$zip = new ZipArchive;
10+
$zip->open($name, ZipArchive::CREATE);
11+
$zip->addFromString('foo.txt', 'foo');
12+
$zip->addFromString('bar.txt', 'bar');
13+
$zip->close();
14+
15+
$zip = new ZipArchive;
16+
$zip->open($name);
17+
18+
$index = $zip->locateName('bar.txt');
19+
$zip->deleteName('bar.txt');
20+
21+
var_dump($zip->getFromName('bar.txt', 0, ZipArchive::FL_UNCHANGED));
22+
var_dump($zip->getFromIndex($index, 0, ZipArchive::FL_UNCHANGED));
23+
24+
$zip->close();
25+
?>
26+
--CLEAN--
27+
<?php
28+
$name = __DIR__ . '/bug_gh21705.zip';
29+
@unlink($name);
30+
?>
31+
--EXPECT--
32+
string(3) "bar"
33+
string(3) "bar"

0 commit comments

Comments
 (0)