Skip to content

Commit c2fbab3

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #77322: PharData::addEmptyDir('/') Possible integer overflow
2 parents 305500a + a53d67c commit c2fbab3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ PHP NEWS
7070

7171
- Phar:
7272
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)
73-
. Fixed #75102 (`PharData` says invalid checksum for valid tar). (cmb)
73+
. Fixed bug #75102 (`PharData` says invalid checksum for valid tar). (cmb)
74+
. Fixed bug #77322 (PharData::addEmptyDir('/') Possible integer overflow).
75+
(cmb)
7476

7577
- Phpdbg:
7678
. Fixed bug #76813 (Access violation near NULL on source operand). (cmb)

ext/phar/tests/bug77322.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #77322 (PharData::addEmptyDir('/') Possible integer overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('phar')) die('skip phar extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$zip = new PharData(__DIR__ . '/bug77322.zip');
10+
$zip->addEmptyDir('/');
11+
var_dump($zip->count());
12+
13+
$tar = new PharData(__DIR__ . '/bug77322.tar');
14+
$tar->addEmptyDir('/');
15+
var_dump($tar->count());
16+
?>
17+
--EXPECT--
18+
int(1)
19+
int(1)
20+
--CLEAN--
21+
<?php
22+
unlink(__DIR__ . '/bug77322.zip');
23+
unlink(__DIR__ . '/bug77322.tar');
24+
?>

ext/phar/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, ch
567567
} else {
568568
etemp.flags = etemp.old_flags = PHAR_ENT_PERM_DEF_FILE;
569569
}
570-
if (is_dir) {
570+
if (is_dir && path_len) {
571571
etemp.filename_len--; /* strip trailing / */
572572
path_len--;
573573
}

0 commit comments

Comments
 (0)