+TODO:
+
+features:
+- stream context option for cleaning crap paths like phar://blah.phar/file//to\\here.php
\ No newline at end of file
phar_close, /* close */
phar_flush, /* flush (does nothing) */
"phar stream",
- NULL, /* seek */
+ phar_seek, /* seek */
NULL, /* cast */
phar_stat, /* stat */
NULL, /* set option */
efree(idata->file);
buffer = idata->data->file;
efree(idata);
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", buffer, internal_file);
efree(internal_file);
return NULL;
}
$file = "<?php
PHP_Archive::mapPhar(5, 'hio', false);
__HALT_COMPILER(); ?>";
-// compressed file length does not include 8 bytes for crc/file length and should
$manifest = pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
$file .= pack('VV', strlen($manifest) + 4, 1) . $manifest . pack('VV', crc32('a'), 1) . 'a';
file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
echo file_get_contents('phar://hio/a');
?>
--EXPECTF--
-Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: data error in %s on line %d
\ No newline at end of file
+Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: decompression failed in %s on line %d
\ No newline at end of file
--- /dev/null
+--TEST--
+url stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+function cleanup() { unlink(dirname(__FILE__) . '/008_phar.php'); }
+register_shutdown_function('cleanup');
+$file = "<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER(); ?>";
+$manifest = '';
+$manifest .= pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 3) . 'b/a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'b/c/d' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'bad/c' . pack('VVVV', 1, time(), 0, 9);
+$file .= pack('VV', strlen($manifest) + 4, 4) .
+ $manifest .
+ pack('VV', crc32('a'), 1) . 'a' .
+ pack('VV', crc32('b'), 1) . 'b';
+ pack('VV', crc32('c'), 1) . 'c';
+ pack('VV', crc32('d'), 1) . 'd';
+file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
+include dirname(__FILE__) . '/008_phar.php';
+var_dump(stat('phar://hio/a'), stat('phar://hio/b'));
+?>
+--EXPECTF--
+array(26) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(0)
+ [2]=>
+ int(33060)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(1)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(0)
+ ["ino"]=>
+ int(0)
+ ["mode"]=>
+ int(33060)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(1)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+}
+array(26) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(0)
+ [2]=>
+ int(16676)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(0)
+ [8]=>
+ int(0)
+ [9]=>
+ int(0)
+ [10]=>
+ int(0)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(0)
+ ["ino"]=>
+ int(0)
+ ["mode"]=>
+ int(16676)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(0)
+ ["atime"]=>
+ int(0)
+ ["mtime"]=>
+ int(0)
+ ["ctime"]=>
+ int(0)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+}
\ No newline at end of file
--- /dev/null
+--TEST--
+stream stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+function cleanup() { unlink(dirname(__FILE__) . '/008_phar.php'); }
+register_shutdown_function('cleanup');
+$file = "<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER(); ?>";
+$manifest = '';
+$manifest .= pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 3) . 'b/a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'b/c/d' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'bad/c' . pack('VVVV', 1, time(), 0, 9);
+$file .= pack('VV', strlen($manifest) + 4, 4) .
+ $manifest .
+ pack('VV', crc32('a'), 1) . 'a' .
+ pack('VV', crc32('b'), 1) . 'b';
+ pack('VV', crc32('c'), 1) . 'c';
+ pack('VV', crc32('d'), 1) . 'd';
+file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
+include dirname(__FILE__) . '/008_phar.php';
+$fp = fopen('phar://hio/a', 'r');
+var_dump(fstat($fp));
+fclose($fp);
+?>
+--EXPECTF--
+array(26) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(0)
+ [2]=>
+ int(33060)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(1)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(0)
+ ["ino"]=>
+ int(0)
+ ["mode"]=>
+ int(33060)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(1)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+}
\ No newline at end of file
--- /dev/null
+--TEST--
+stream stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+function cleanup() { unlink(dirname(__FILE__) . '/008_phar.php'); }
+register_shutdown_function('cleanup');
+$file = "<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER(); ?>";
+$contents = 'abcdefg';
+$manifest = pack('V', 1) . 'a' . pack('VVVV', strlen($contents), time(), 0, 8 + strlen($contents));
+$file .= pack('VV', strlen($manifest) + 4, 1) .
+ $manifest .
+ pack('VV', crc32($contents), strlen($contents)) . $contents;
+file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
+include dirname(__FILE__) . '/008_phar.php';
+$fp = fopen('phar://hio/a', 'r');
+var_dump(ftell($fp));
+echo 'fseek($fp, 1)';var_dump(fseek($fp, 1));
+var_dump(ftell($fp));
+echo 'fseek($fp, 1, SEEK_CUR)';var_dump(fseek($fp, 1, SEEK_CUR));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1, SEEK_CUR)';var_dump(fseek($fp, -1, SEEK_CUR));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1, SEEK_END)';var_dump(fseek($fp, -1, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -8, SEEK_END)';var_dump(fseek($fp, -8, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -7, SEEK_END)';var_dump(fseek($fp, -7, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 0, SEEK_END)';var_dump(fseek($fp, 0, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 1, SEEK_END)';var_dump(fseek($fp, 1, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -8, SEEK_END)';var_dump(fseek($fp, -8, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 6)';var_dump(fseek($fp, 6));
+var_dump(ftell($fp));
+echo 'fseek($fp, 8)';var_dump(fseek($fp, 8));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1)';var_dump(fseek($fp, -1));
+var_dump(ftell($fp));
+echo "next\n";
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, -5, SEEK_CUR)';var_dump(fseek($fp, -5, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, 5, SEEK_CUR)';var_dump(fseek($fp, 5, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, -4, SEEK_CUR)';var_dump(fseek($fp, -4, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, 3, SEEK_CUR)';var_dump(fseek($fp, 3, SEEK_CUR));
+var_dump(ftell($fp));
+fclose($fp);
+?>
+--EXPECT--
+int(0)
+fseek($fp, 1)int(0)
+int(1)
+fseek($fp, 1, SEEK_CUR)int(0)
+int(2)
+fseek($fp, -1, SEEK_CUR)int(0)
+int(1)
+fseek($fp, -1, SEEK_END)int(0)
+int(6)
+fseek($fp, -8, SEEK_END)int(-1)
+bool(false)
+fseek($fp, -7, SEEK_END)int(0)
+int(0)
+fseek($fp, 0, SEEK_END)int(0)
+int(7)
+fseek($fp, 1, SEEK_END)int(-1)
+bool(false)
+fseek($fp, -8, SEEK_END)int(-1)
+bool(false)
+fseek($fp, 6)int(0)
+int(6)
+fseek($fp, 8)int(-1)
+bool(false)
+fseek($fp, -1)int(-1)
+bool(false)
+next
+int(4)
+fseek($fp, -5, SEEK_CUR)int(-1)
+bool(false)
+int(4)
+fseek($fp, 5, SEEK_CUR)int(-1)
+bool(false)
+int(4)
+fseek($fp, -4, SEEK_CUR)int(0)
+int(0)
+int(4)
+fseek($fp, 3, SEEK_CUR)int(0)
+int(7)
+
+
+
+
+
+
+
+
+
+