]> granicus.if.org Git - php/commitdiff
Fixed bug#53872 (internal corruption of phar)
authorHannes Magnusson <bjori@php.net>
Mon, 29 Aug 2011 16:05:45 +0000 (16:05 +0000)
committerHannes Magnusson <bjori@php.net>
Mon, 29 Aug 2011 16:05:45 +0000 (16:05 +0000)
ext/phar/tests/bug53872.phpt [new file with mode: 0644]
ext/phar/tests/bug53872/first.txt [new file with mode: 0644]
ext/phar/tests/bug53872/second.txt [new file with mode: 0644]
ext/phar/tests/bug53872/third.txt [new file with mode: 0644]
ext/phar/util.c

diff --git a/ext/phar/tests/bug53872.phpt b/ext/phar/tests/bug53872.phpt
new file mode 100644 (file)
index 0000000..490ae6f
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--\r
+bug#53872 (internal corruption of phar)\r
+--INI--\r
+phar.readonly=0\r
+--FILE--\r
+<?php\r
+$p=new Phar('bug53872-phar.phar');\r
+$p->buildFromDirectory(__DIR__ . "/bug53872/");\r
+$p->setStub('<?php __HALT_COMPILER();?\>');\r
+$p->compressFiles(Phar::GZ);\r
+\r
+print(file_get_contents('phar://bug53872-phar.phar/first.txt'));\r
+print(file_get_contents('phar://bug53872-phar.phar/second.txt'));\r
+print(file_get_contents('phar://bug53872-phar.phar/third.txt'));\r
+?>\r
+--CLEAN--\r
+<?php\r
+unlink("bug53872-phar.phar");\r
+?>\r
+--EXPECT--\r
+content of first.txt\r
+content of third.txt\r
+\r
diff --git a/ext/phar/tests/bug53872/first.txt b/ext/phar/tests/bug53872/first.txt
new file mode 100644 (file)
index 0000000..90a4d1f
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/ext/phar/tests/bug53872/third.txt b/ext/phar/tests/bug53872/third.txt
new file mode 100644 (file)
index 0000000..4f283cd
--- /dev/null
@@ -0,0 +1 @@
+content of third.txt
index 22403e8ff0b3b25bcd90cd9a241e898f4cfa5ddc..22c99bb8d9cedd8ce7f098cf878ff62a0a25cfee 100644 (file)
@@ -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);