summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Magnusson <bjori@php.net>2011-08-29 16:05:45 +0000
committerHannes Magnusson <bjori@php.net>2011-08-29 16:05:45 +0000
commit8e74e304119826ac7de28081a471482155e93bb4 (patch)
tree2d38500a16e9c0b98f03c6746045dfa2aa96bb81
parent1f4dfded592909a162f4b590a25edc681e6b338d (diff)
downloadphp-git-8e74e304119826ac7de28081a471482155e93bb4.tar.gz
Fixed bug#53872 (internal corruption of phar)
-rw-r--r--ext/phar/tests/bug53872.phpt23
-rw-r--r--ext/phar/tests/bug53872/first.txt1
-rw-r--r--ext/phar/tests/bug53872/second.txt0
-rw-r--r--ext/phar/tests/bug53872/third.txt1
-rw-r--r--ext/phar/util.c10
5 files changed, 31 insertions, 4 deletions
diff --git a/ext/phar/tests/bug53872.phpt b/ext/phar/tests/bug53872.phpt
new file mode 100644
index 0000000000..490ae6fd4c
--- /dev/null
+++ b/ext/phar/tests/bug53872.phpt
@@ -0,0 +1,23 @@
+--TEST--
+bug#53872 (internal corruption of phar)
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$p=new Phar('bug53872-phar.phar');
+$p->buildFromDirectory(__DIR__ . "/bug53872/");
+$p->setStub('<?php __HALT_COMPILER();?\>');
+$p->compressFiles(Phar::GZ);
+
+print(file_get_contents('phar://bug53872-phar.phar/first.txt'));
+print(file_get_contents('phar://bug53872-phar.phar/second.txt'));
+print(file_get_contents('phar://bug53872-phar.phar/third.txt'));
+?>
+--CLEAN--
+<?php
+unlink("bug53872-phar.phar");
+?>
+--EXPECT--
+content of first.txt
+content of third.txt
+
diff --git a/ext/phar/tests/bug53872/first.txt b/ext/phar/tests/bug53872/first.txt
new file mode 100644
index 0000000000..90a4d1f092
--- /dev/null
+++ b/ext/phar/tests/bug53872/first.txt
@@ -0,0 +1 @@
+content of first.txt
diff --git a/ext/phar/tests/bug53872/second.txt b/ext/phar/tests/bug53872/second.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/ext/phar/tests/bug53872/second.txt
diff --git a/ext/phar/tests/bug53872/third.txt b/ext/phar/tests/bug53872/third.txt
new file mode 100644
index 0000000000..4f283cd78f
--- /dev/null
+++ b/ext/phar/tests/bug53872/third.txt
@@ -0,0 +1 @@
+content of third.txt
diff --git a/ext/phar/util.c b/ext/phar/util.c
index 22403e8ff0..22c99bb8d9 100644
--- a/ext/phar/util.c
+++ b/ext/phar/util.c
@@ -999,10 +999,12 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
php_stream_filter_append(&ufp->writefilters, filter);
php_stream_seek(phar_get_entrypfp(entry TSRMLS_CC), phar_get_fp_offset(entry TSRMLS_CC), SEEK_SET);
- if (SUCCESS != phar_stream_copy_to_stream(phar_get_entrypfp(entry TSRMLS_CC), ufp, entry->compressed_filesize, NULL)) {
- spprintf(error, 4096, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", phar->fname, entry->filename);
- php_stream_filter_remove(filter, 1 TSRMLS_CC);
- return FAILURE;
+ if (entry->uncompressed_filesize) {
+ if (SUCCESS != phar_stream_copy_to_stream(phar_get_entrypfp(entry TSRMLS_CC), ufp, entry->compressed_filesize, NULL)) {
+ spprintf(error, 4096, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", phar->fname, entry->filename);
+ php_stream_filter_remove(filter, 1 TSRMLS_CC);
+ return FAILURE;
+ }
}
php_stream_filter_flush(filter, 1);