]> 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)
NEWS
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/NEWS b/NEWS
index d34da25b4be6d56e7f5b4d387eb1d7e696c2b288..fd58463c302336f72a3a5edaddf1bdf66c958df6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP                                                                        NEWS
 
 - Phar:
   . Fixed bug#52013 (Unable to decompress files in a compressed phar). (Hannes)
+  . Fixed bug#53872 (internal corruption of phar). (Hannes)
 
 - NSAPI SAPI:
   . Don't set $_SERVER['HTTPS'] on unsecure connection (bug #55403). (Uwe
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 4706571b06225869a7eee2fe5846f8b7117f43cf..9b0d8d91c2e6d0ad99a81516eddb1a83e4cda201 100644 (file)
@@ -1000,10 +1000,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);