Fix bug #69958 - Segfault in Phar::convertToData on invalid file

This commit is contained in:
Stanislav Malyshev 2015-07-04 21:01:50 -07:00
parent 5df893ce3c
commit 00f177a5ed
3 changed files with 17 additions and 1 deletions

View file

@ -2296,7 +2296,9 @@ no_copy:
zend_hash_destroy(&(phar->manifest));
zend_hash_destroy(&(phar->mounted_dirs));
zend_hash_destroy(&(phar->virtual_dirs));
php_stream_close(phar->fp);
if (phar->fp) {
php_stream_close(phar->fp);
}
efree(phar->fname);
efree(phar);
return NULL;

View file

@ -0,0 +1,14 @@
--TEST--
Phar: bug #69958: Segfault in Phar::convertToData on invalid file
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--FILE--
<?php
$tarphar = new PharData(__DIR__.'/bug69958.tar');
$phar = $tarphar->convertToData(Phar::TAR);
--EXPECTF--
Fatal error: Uncaught exception 'BadMethodCallException' with message 'phar "%s/bug69958.tar" exists and must be unlinked prior to conversion' in %s/bug69958.php:%d
Stack trace:
#0 %s/bug69958.php(%d): PharData->convertToData(%d)
#1 {main}
thrown in %s/bug69958.php on line %d

BIN
ext/phar/tests/bug69958.tar Normal file

Binary file not shown.