Skip to content

Commit b28b8b2

Browse files
committed
Fix bug #73768 - Memory corruption when loading hostile phar
1 parent ca46d0a commit b28b8b2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

ext/phar/phar.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,14 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char
981981
/* if the alias is stored we enforce it (implicit overrides explicit) */
982982
if (alias && alias_len && (alias_len != (int)tmp_len || strncmp(alias, buffer, tmp_len)))
983983
{
984-
buffer[tmp_len] = '\0';
985984
php_stream_close(fp);
986985

987986
if (signature) {
988987
efree(signature);
989988
}
990989

991990
if (error) {
992-
spprintf(error, 0, "cannot load phar \"%s\" with implicit alias \"%s\" under different alias \"%s\"", fname, buffer, alias);
991+
spprintf(error, 0, "cannot load phar \"%s\" with implicit alias \"%.*s\" under different alias \"%s\"", fname, tmp_len, buffer, alias);
993992
}
994993

995994
efree(savebuf);

ext/phar/tests/bug73768.phar

219 Bytes
Binary file not shown.

ext/phar/tests/bug73768.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Phar: PHP bug #73768: Memory corruption when loading hostile phar
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
chdir(__DIR__);
8+
try {
9+
$p = Phar::LoadPhar('bug73768.phar', 'alias.phar');
10+
echo "OK\n";
11+
} catch(PharException $e) {
12+
echo $e->getMessage();
13+
}
14+
?>
15+
--EXPECTF--
16+
cannot load phar "%sbug73768.phar" with implicit alias "" under different alias "alias.phar"

0 commit comments

Comments
 (0)