Skip to content

Commit c27f012

Browse files
committed
Fix bug #69453 - don't try to cut empty string
1 parent ac28329 commit c27f012

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ext/phar/tar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias,
425425
entry.filename_len = i;
426426
entry.filename = pestrndup(hdr->name, i, myphar->is_persistent);
427427

428-
if (entry.filename[entry.filename_len - 1] == '/') {
428+
if (i > 0 && entry.filename[entry.filename_len - 1] == '/') {
429429
/* some tar programs store directories with trailing slash */
430430
entry.filename[entry.filename_len - 1] = '\0';
431431
entry.filename_len--;

ext/phar/tests/bug69453.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Phar: bug #69453: Memory Corruption in phar_parse_tarfile when entry filename starts with null
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
$fname = dirname(__FILE__) . '/bug69453.tar.phar';
8+
try {
9+
$r = new Phar($fname, 0);
10+
} catch(UnexpectedValueException $e) {
11+
echo $e;
12+
}
13+
?>
14+
15+
==DONE==
16+
--EXPECTF--
17+
exception 'UnexpectedValueException' with message 'phar error: "%s/bug69453.tar.phar" is a corrupted tar file (checksum mismatch of file "")' in %s:%d
18+
Stack trace:
19+
#0 %s/bug69453.php(%d): Phar->__construct('%s', 0)
20+
#1 {main}
21+
==DONE==

0 commit comments

Comments
 (0)