Skip to content

Commit 6b37cdd

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #77322: PharData::addEmptyDir('/') Possible integer overflow
2 parents 6e2614e + c2fbab3 commit 6b37cdd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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)