Browse Source
- Fix a memleak
- Fix a memleak
- Fix uninitialized mem access - Fix/improve error handling - Add INI entry phar.readonly - Add testsmigration/RELEASE_1_0_0
13 changed files with 376 additions and 18 deletions
-
119ext/phar/phar.c
-
2ext/phar/tests/create_new_phar.phpt
-
28ext/phar/tests/create_new_phar_b.phpt
-
9ext/phar/tests/delete_in_phar.phpt
-
56ext/phar/tests/delete_in_phar_b.phpt
-
2ext/phar/tests/open_for_write_existing.phpt
-
43ext/phar/tests/open_for_write_existing_b.phpt
-
2ext/phar/tests/open_for_write_newfile.phpt
-
53ext/phar/tests/open_for_write_newfile_b.phpt
-
2ext/phar/tests/phar_oo_011.phpt
-
37ext/phar/tests/phar_oo_011b.phpt
-
2ext/phar/tests/phar_oo_012.phpt
-
39ext/phar/tests/phar_oo_012b.phpt
@ -0,0 +1,28 @@ |
|||
--TEST-- |
|||
Phar: create a completely new phar |
|||
--SKIPIF-- |
|||
<?php if (!extension_loaded("phar")) print "skip"; ?> |
|||
--INI-- |
|||
phar.readonly=1 |
|||
--FILE-- |
|||
<?php |
|||
|
|||
file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php', |
|||
'brand new!'); |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php'; |
|||
?> |
|||
|
|||
===DONE=== |
|||
--CLEAN-- |
|||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d |
|||
|
|||
Warning: include(%screate_new_phar_b.phar.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d |
|||
|
|||
Warning: include(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d |
|||
|
|||
Warning: include(): Failed opening 'phar://%screate_new_phar_b.phar.php/a.php' for inclusion (include_path='.') in %screate_new_phar_b.php on line %d |
|||
|
|||
===DONE=== |
|||
@ -0,0 +1,56 @@ |
|||
--TEST-- |
|||
Phar: delete a file within a .phar |
|||
--SKIPIF-- |
|||
<?php if (!extension_loaded("phar")) print "skip"; ?> |
|||
--INI-- |
|||
phar.readonly=1 |
|||
--FILE-- |
|||
<?php |
|||
$file = "<?php __HALT_COMPILER(); ?>"; |
|||
|
|||
$files = array(); |
|||
$files['a.php'] = '<?php echo "This is a\n"; ?>'; |
|||
$files['b.php'] = '<?php echo "This is b\n"; ?>'; |
|||
$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; |
|||
$manifest = ''; |
|||
foreach($files as $name => $cont) { |
|||
$len = strlen($cont); |
|||
$manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00); |
|||
} |
|||
$alias = ''; |
|||
$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest; |
|||
$file .= pack('V', strlen($manifest)) . $manifest; |
|||
foreach($files as $cont) |
|||
{ |
|||
$file .= $cont; |
|||
} |
|||
|
|||
file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file); |
|||
|
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php'; |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b.php'; |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; |
|||
unlink('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'); |
|||
?> |
|||
===AFTER=== |
|||
<?php |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php'; |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b.php'; |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; |
|||
?> |
|||
|
|||
===DONE=== |
|||
--CLEAN-- |
|||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> |
|||
--EXPECTF-- |
|||
This is a |
|||
This is b |
|||
This is b/c |
|||
|
|||
Warning: unlink(): phar error: write operations disabled by INI setting in %sdelete_in_phar_b.php on line %d |
|||
===AFTER=== |
|||
This is a |
|||
This is b |
|||
This is b/c |
|||
|
|||
===DONE=== |
|||
@ -0,0 +1,43 @@ |
|||
--TEST-- |
|||
Phar: fopen a .phar for writing (existing file) |
|||
--SKIPIF-- |
|||
<?php if (!extension_loaded("phar")) print "skip"; ?> |
|||
--INI-- |
|||
phar.readonly=1 |
|||
--FILE-- |
|||
<?php |
|||
$file = "<?php __HALT_COMPILER(); ?>"; |
|||
|
|||
$files = array(); |
|||
$files['a.php'] = '<?php echo "This is a\n"; ?>'; |
|||
$files['b.php'] = '<?php echo "This is b\n"; ?>'; |
|||
$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; |
|||
$manifest = ''; |
|||
foreach($files as $name => $cont) { |
|||
$len = strlen($cont); |
|||
$manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00); |
|||
} |
|||
$alias = ''; |
|||
$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest; |
|||
$file .= pack('V', strlen($manifest)) . $manifest; |
|||
foreach($files as $cont) |
|||
{ |
|||
$file .= $cont; |
|||
} |
|||
|
|||
file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file); |
|||
|
|||
$fp = fopen('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php', 'wb'); |
|||
fwrite($fp, 'extra'); |
|||
fclose($fp); |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; |
|||
?> |
|||
===DONE=== |
|||
--CLEAN-- |
|||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: include(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: internal corruption of phar "%sopen_for_write_existing_b.phar.php" (crc32 mismatch on file "b/c.php") in %sopen_for_write_existing_b.php on line %d |
|||
|
|||
Warning: include(): Failed opening 'phar://%sopen_for_write_existing_b.phar.php/b/c.php' for inclusion (include_path='.') in %sopen_for_write_existing_b.php on line %d |
|||
===DONE=== |
|||
@ -0,0 +1,53 @@ |
|||
--TEST-- |
|||
Phar: fopen a .phar for writing (new file) |
|||
--SKIPIF-- |
|||
<?php if (!extension_loaded("phar")) print "skip"; ?> |
|||
--INI-- |
|||
phar.readonly=1 |
|||
--FILE-- |
|||
<?php |
|||
$file = "<?php __HALT_COMPILER(); ?>"; |
|||
|
|||
$files = array(); |
|||
$files['a.php'] = '<?php echo "This is a\n"; ?>'; |
|||
$files['b.php'] = '<?php echo "This is b\n"; ?>'; |
|||
$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; |
|||
$manifest = ''; |
|||
foreach($files as $name => $cont) { |
|||
$len = strlen($cont); |
|||
$manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00); |
|||
} |
|||
$alias = ''; |
|||
$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest; |
|||
$file .= pack('V', strlen($manifest)) . $manifest; |
|||
foreach($files as $cont) |
|||
{ |
|||
$file .= $cont; |
|||
} |
|||
|
|||
file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file); |
|||
|
|||
$fp = fopen('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php', 'wb'); |
|||
fwrite($fp, 'extra'); |
|||
fclose($fp); |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; |
|||
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php'; |
|||
?> |
|||
|
|||
===DONE=== |
|||
--CLEAN-- |
|||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line %d |
|||
|
|||
Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d |
|||
|
|||
Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d |
|||
This is b/c |
|||
|
|||
Warning: include(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line %d |
|||
|
|||
Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.php/b/new.php' for inclusion (include_path='.') in %sopen_for_write_newfile_b.php on line %d |
|||
|
|||
===DONE=== |
|||
@ -0,0 +1,37 @@ |
|||
--TEST-- |
|||
Phar object: add file |
|||
--SKIPIF-- |
|||
<?php if (!extension_loaded('phar')) die('skip'); ?> |
|||
--INI-- |
|||
phar.readonly=1 |
|||
--FILE-- |
|||
<?php |
|||
|
|||
try |
|||
{ |
|||
$pharconfig = 0; |
|||
|
|||
require_once 'phar_oo_test.inc'; |
|||
|
|||
$phar = new Phar($fname); |
|||
|
|||
$phar['f.php'] = 'hi'; |
|||
var_dump(isset($phar['f.php'])); |
|||
echo $phar['f.php']; |
|||
echo "\n"; |
|||
} |
|||
catch (BadMethodCallException $e) |
|||
{ |
|||
echo "Exception: " . $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
?> |
|||
===DONE=== |
|||
--CLEAN-- |
|||
<?php |
|||
unlink(dirname(__FILE__) . '/phar_oo_test.phar.php'); |
|||
__halt_compiler(); |
|||
?> |
|||
--EXPECTF-- |
|||
Exception: Write operations disabled by INI setting |
|||
===DONE=== |
|||
@ -0,0 +1,39 @@ |
|||
--TEST-- |
|||
Phar object: unset file |
|||
--SKIPIF-- |
|||
<?php if (!extension_loaded('phar')) die('skip'); ?> |
|||
--INI-- |
|||
phar.readonly=1 |
|||
--FILE-- |
|||
<?php |
|||
|
|||
try |
|||
{ |
|||
$pharconfig = 0; |
|||
|
|||
require_once 'phar_oo_test.inc'; |
|||
|
|||
$phar = new Phar($fname); |
|||
|
|||
$phar['f.php'] = 'hi'; |
|||
var_dump(isset($phar['f.php'])); |
|||
echo $phar['f.php']; |
|||
echo "\n"; |
|||
unset($phar['f.php']); |
|||
var_dump(isset($phar['f.php'])); |
|||
} |
|||
catch (BadMethodCallException $e) |
|||
{ |
|||
echo "Exception: " . $e->getMessage() . "\n"; |
|||
} |
|||
|
|||
?> |
|||
===DONE=== |
|||
--CLEAN-- |
|||
<?php |
|||
unlink(dirname(__FILE__) . '/phar_oo_test.phar.php'); |
|||
__halt_compiler(); |
|||
?> |
|||
--EXPECTF-- |
|||
Exception: Write operations disabled by INI setting |
|||
===DONE=== |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue