johannes                                 Thu, 12 Nov 2009 17:43:23 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=290601

Log:
Merge 290527 (fix PHP Bug #49910: no support for ././@LongLink for long
filenames in phar tar support) (Greg)

Bug: http://bugs.php.net/49910 (Assigned) no support for ././@LongLink for long 
filenames in phar tar support
      
Changed paths:
    UU  php/php-src/branches/PHP_5_3_1/NEWS
    U   php/php-src/branches/PHP_5_3_1/ext/phar/php_phar.h
    U   php/php-src/branches/PHP_5_3_1/ext/phar/tar.c
    A   php/php-src/branches/PHP_5_3_1/ext/phar/tests/tar/bug49910.phpt
    A + 
php/php-src/branches/PHP_5_3_1/ext/phar/tests/tar/files/Structures_Graph-1.0.3.tgz
        (from 
php/php-src/branches/PHP_5_3/ext/phar/tests/tar/files/Structures_Graph-1.0.3.tgz:r290527)

Modified: php/php-src/branches/PHP_5_3_1/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3_1/NEWS	2009-11-12 17:43:04 UTC (rev 290600)
+++ php/php-src/branches/PHP_5_3_1/NEWS	2009-11-12 17:43:23 UTC (rev 290601)
@@ -5,6 +5,8 @@

 - Fixed bug #50063 (safe_mode_include_dir fails). (Johannes, christian at
   elmerot dot se)
+- Fixed bug #49910 (no support for ././@LongLink for long filenames in phar
+  tar support). (Greg)

 03 Nov 2009, PHP 5.3.1 RC3
 - Added "max_file_uploads" INI directive, which can be set to limit the


Property changes on: php/php-src/branches/PHP_5_3_1/NEWS
___________________________________________________________________
Modified: svn:mergeinfo
   - /php/php-src/branches/PHP_5_3/NEWS:288028,288034,288067,288081,288083,288085,288087-288088,288096,288111,288116-288117,288159,288202-288204,288208,288215,288246,288263,288265,288267,288329,288339,288351,288354,288378-288379,288393,288396,288411,288437,288439,288446-288448,288462,288510-288511,288514-288518,288522-288524,288531,288537,288541,288547-288548,288555,288562,288571,288575,288580,288583,288585,288598,288603,288638,288644,288653,288676,288679,288705,288741,288743,288745-288747,288749,288784,288793,288834,288892-288893,288896,288940,288943,288945,288953,288973,289004,289019,289027-289028,289030,289039,289046,289049,289076,289123,289214,289216,289247,289249,289285,289339,289341,289351,289366,289368,289372,289445-289446,289531,289546-289547,289557,289568,289581,289587,289612,289621-289624,289666-289667,289779,289987,289990,290029,290129,290147,290306
/php/php-src/trunk/NEWS:284726
   + /php/php-src/branches/PHP_5_3/NEWS:288028,288034,288067,288081,288083,288085,288087-288088,288096,288111,288116-288117,288159,288202-288204,288208,288215,288246,288263,288265,288267,288329,288339,288351,288354,288378-288379,288393,288396,288411,288437,288439,288446-288448,288462,288510-288511,288514-288518,288522-288524,288531,288537,288541,288547-288548,288555,288562,288571,288575,288580,288583,288585,288598,288603,288638,288644,288653,288676,288679,288705,288741,288743,288745-288747,288749,288784,288793,288834,288892-288893,288896,288940,288943,288945,288953,288973,289004,289019,289027-289028,289030,289039,289046,289049,289076,289123,289214,289216,289247,289249,289285,289339,289341,289351,289366,289368,289372,289445-289446,289531,289546-289547,289557,289568,289581,289587,289612,289621-289624,289666-289667,289779,289987,289990,290029,290129,290147,290306,290527
/php/php-src/trunk/NEWS:284726

Modified: php/php-src/branches/PHP_5_3_1/ext/phar/php_phar.h
===================================================================
--- php/php-src/branches/PHP_5_3_1/ext/phar/php_phar.h	2009-11-12 17:43:04 UTC (rev 290600)
+++ php/php-src/branches/PHP_5_3_1/ext/phar/php_phar.h	2009-11-12 17:43:23 UTC (rev 290601)
@@ -22,7 +22,7 @@
 #ifndef PHP_PHAR_H
 #define PHP_PHAR_H

-#define PHP_PHAR_VERSION "2.0.0"
+#define PHP_PHAR_VERSION "2.0.1"

 #include "ext/standard/basic_functions.h"
 extern zend_module_entry phar_module_entry;

Modified: php/php-src/branches/PHP_5_3_1/ext/phar/tar.c
===================================================================
--- php/php-src/branches/PHP_5_3_1/ext/phar/tar.c	2009-11-12 17:43:04 UTC (rev 290600)
+++ php/php-src/branches/PHP_5_3_1/ext/phar/tar.c	2009-11-12 17:43:23 UTC (rev 290601)
@@ -200,6 +200,7 @@
 	tar_header *hdr;
 	php_uint32 sum1, sum2, size, old;
 	phar_archive_data *myphar, **actual;
+	int last_was_longlink = 0;

 	if (error) {
 		*error = NULL;
@@ -332,7 +333,52 @@
 			goto bail;
 		}

-		if (!old && hdr->prefix[0] != 0) {
+		if (!last_was_longlink && hdr->typeflag == 'L') {
+			last_was_longlink = 1;
+			/* support the ././@LongLink system for storing long filenames */
+			entry.filename_len = entry.uncompressed_filesize;
+			entry.filename = pemalloc(entry.filename_len+1, myphar->is_persistent);
+
+			read = php_stream_read(fp, entry.filename, entry.filename_len);
+			if (read != entry.filename_len) {
+				efree(entry.filename);
+				if (error) {
+					spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
+				}
+				php_stream_close(fp);
+				phar_destroy_phar_data(myphar TSRMLS_CC);
+				return FAILURE;
+			}
+			entry.filename[entry.filename_len] = '\0';
+
+			/* skip blank stuff */
+			size = ((size+511)&~511) - size;
+
+			/* this is not good enough - seek succeeds even on truncated tars */
+			php_stream_seek(fp, size, SEEK_CUR);
+			if ((uint)php_stream_tell(fp) > totalsize) {
+				efree(entry.filename);
+				if (error) {
+					spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
+				}
+				php_stream_close(fp);
+				phar_destroy_phar_data(myphar TSRMLS_CC);
+				return FAILURE;
+			}
+
+			read = php_stream_read(fp, buf, sizeof(buf));
+
+			if (read != sizeof(buf)) {
+				efree(entry.filename);
+				if (error) {
+					spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
+				}
+				php_stream_close(fp);
+				phar_destroy_phar_data(myphar TSRMLS_CC);
+				return FAILURE;
+			}
+			continue;
+		} else if (!last_was_longlink && !old && hdr->prefix[0] != 0) {
 			char name[256];
 			int i, j;

@@ -357,7 +403,7 @@
 				entry.filename_len--;
 			}
 			entry.filename = pestrndup(name, entry.filename_len, myphar->is_persistent);
-		} else {
+		} else if (!last_was_longlink) {
 			int i;

 			/* calculate strlen, which can be no longer than 100 */
@@ -375,6 +421,7 @@
 				entry.filename_len--;
 			}
 		}
+		last_was_longlink = 0;

 		phar_add_virtual_dirs(myphar, entry.filename, entry.filename_len TSRMLS_CC);


Added: php/php-src/branches/PHP_5_3_1/ext/phar/tests/tar/bug49910.phpt
===================================================================
--- php/php-src/branches/PHP_5_3_1/ext/phar/tests/tar/bug49910.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3_1/ext/phar/tests/tar/bug49910.phpt	2009-11-12 17:43:23 UTC (rev 290601)
@@ -0,0 +1,49 @@
+--TEST--
+Bug #49910: no support for ././@LongLink for long filenames in phar tar support
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = str_replace('\\', '/', dirname(__FILE__) . '/files/Structures_Graph-1.0.3.tgz');
+$tar = new PharData($fname);
+$files = array();
+foreach (new RecursiveIteratorIterator($tar) as $file) {
+	$files[] = str_replace($fname, '*', $file->getPathName());
+}
+print_r($files);
+?>
+===DONE===
+--EXPECT--
+Array
+(
+    [0] => phar://*/Structures_Graph-1.0.3/LICENSE
+    [1] => phar://*/Structures_Graph-1.0.3/Structures/Graph/Manipulator/AcyclicTest.php
+    [2] => phar://*/Structures_Graph-1.0.3/Structures/Graph/Manipulator/TopologicalSorter.php
+    [3] => phar://*/Structures_Graph-1.0.3/Structures/Graph/Node.php
+    [4] => phar://*/Structures_Graph-1.0.3/Structures/Graph.php
+    [5] => phar://*/Structures_Graph-1.0.3/docs/generate.sh
+    [6] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/Structures_Graph.html
+    [7] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/Structures_Graph_Manipulator_AcyclicTest.html
+    [8] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/Structures_Graph_Manipulator_TopologicalSorter.html
+    [9] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/Structures_Graph_Node.html
+    [10] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/_Structures_Graph_Manipulator_AcyclicTest_php.html
+    [11] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/_Structures_Graph_Manipulator_TopologicalSorter_php.html
+    [12] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/_Structures_Graph_Node_php.html
+    [13] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/_Structures_Graph_php.html
+    [14] => phar://*/Structures_Graph-1.0.3/docs/html/Structures_Graph/tutorial_Structures_Graph.pkg.html
+    [15] => phar://*/Structures_Graph-1.0.3/docs/html/classtrees_Structures_Graph.html
+    [16] => phar://*/Structures_Graph-1.0.3/docs/html/elementindex.html
+    [17] => phar://*/Structures_Graph-1.0.3/docs/html/elementindex_Structures_Graph.html
+    [18] => phar://*/Structures_Graph-1.0.3/docs/html/errors.html
+    [19] => phar://*/Structures_Graph-1.0.3/docs/html/index.html
+    [20] => phar://*/Structures_Graph-1.0.3/docs/html/li_Structures_Graph.html
+    [21] => phar://*/Structures_Graph-1.0.3/docs/html/media/banner.css
+    [22] => phar://*/Structures_Graph-1.0.3/docs/html/media/stylesheet.css
+    [23] => phar://*/Structures_Graph-1.0.3/docs/html/packages.html
+    [24] => phar://*/Structures_Graph-1.0.3/docs/html/todolist.html
+    [25] => phar://*/Structures_Graph-1.0.3/docs/tutorials/Structures_Graph/Structures_Graph.pkg
+    [26] => phar://*/Structures_Graph-1.0.3/tests/AllTests.php
+    [27] => phar://*/Structures_Graph-1.0.3/tests/testCase/BasicGraph.php
+    [28] => phar://*/package.xml
+)
+===DONE===
\ No newline at end of file

Copied: php/php-src/branches/PHP_5_3_1/ext/phar/tests/tar/files/Structures_Graph-1.0.3.tgz (from rev 290527, php/php-src/branches/PHP_5_3/ext/phar/tests/tar/files/Structures_Graph-1.0.3.tgz)
===================================================================
(Binary files differ)
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to