Skip to content

Commit 5b2d4c0

Browse files
committed
Fix #79315 ZipArchive::addFile doesn't honor start/length parameters
1 parent 2aecf3a commit 5b2d4c0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PHP NEWS
2424
- Standard:
2525
. Fixed bug #79254 (getenv() w/o arguments not showing changes). (cmb)
2626

27+
- Zip:
28+
. Fixed bug #79315 (ZipArchive::addFile doesn't honor start/length
29+
parameters). (Remi)
30+
2731
20 Feb 2020, PHP 7.3.15
2832

2933
- Core:

ext/zip/php_zip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,8 @@ static ZIPARCHIVE_METHOD(addFile)
18241824
entry_name_len = ZSTR_LEN(filename);
18251825
}
18261826

1827-
if (php_zip_add_file(intern, ZSTR_VAL(filename), ZSTR_LEN(filename), entry_name, entry_name_len, 0, 0) < 0) {
1827+
if (php_zip_add_file(intern, ZSTR_VAL(filename), ZSTR_LEN(filename),
1828+
entry_name, entry_name_len, offset_start, offset_len) < 0) {
18281829
RETURN_FALSE;
18291830
} else {
18301831
RETURN_TRUE;

ext/zip/tests/oo_addfile.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ if (!$zip->open($file)) {
2020
if (!$zip->addFile($dirname . 'utils.inc', 'test.php')) {
2121
echo "failed\n";
2222
}
23+
if (!$zip->addFile($dirname . 'utils.inc', 'mini.txt', 12, 34)) {
24+
echo "failed\n";
25+
}
2326
if ($zip->status == ZIPARCHIVE::ER_OK) {
2427
dump_entries_name($zip);
2528
$zip->close();
2629
} else {
2730
echo "failed\n";
2831
}
32+
if (!$zip->open($file)) {
33+
exit('failed');
34+
}
35+
var_dump(strlen($zip->getFromName('test.php')) == filesize($dirname . 'utils.inc'));
36+
var_dump(strlen($zip->getFromName('mini.txt')) == 34);
2937
@unlink($file);
3038
?>
3139
--EXPECT--
@@ -34,3 +42,6 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
3442
2 foobar/baz
3543
3 entry1.txt
3644
4 test.php
45+
5 mini.txt
46+
bool(true)
47+
bool(true)

0 commit comments

Comments
 (0)