cellog                                   Thu, 23 Jul 2009 16:30:27 +0000

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

Log:
fix PHP bug #48791: open office files always reported as corrupted

Bug: http://bugs.php.net/48791 (Open) open office files always reported as 
corrupted
      
Changed paths:
    U   pecl/phar/trunk/package.php
    U   pecl/phar/trunk/phar.c
    U   pecl/phar/trunk/pharzip.h
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/phar/phar.c
    U   php/php-src/branches/PHP_5_3/ext/phar/pharzip.h
    U   php/php-src/trunk/ext/phar/phar.c
    U   php/php-src/trunk/ext/phar/pharzip.h

Modified: pecl/phar/trunk/package.php
===================================================================
--- pecl/phar/trunk/package.php	2009-07-23 16:28:17 UTC (rev 284657)
+++ pecl/phar/trunk/package.php	2009-07-23 16:30:27 UTC (rev 284658)
@@ -48,6 +48,7 @@
  getSignature() call
  fixed PHP Bug #49020: phar misinterprets ustar long filename standard
  fixed PHP Bug #49018: phar tar stores long filenames with prefix/name reversed
+ fixed PHP Bug #48791: open office files always reported as corrupted
  fixed PHP Bug #48783: make install will fail saying phar file exists
  fixed PHP Bug #48740: PHAR install fails when INSTALL_ROOT is not the final install location
  fixed PHP Bug #48681: openssl signature verification for tar archives broken

Modified: pecl/phar/trunk/phar.c
===================================================================
--- pecl/phar/trunk/phar.c	2009-07-23 16:28:17 UTC (rev 284657)
+++ pecl/phar/trunk/phar.c	2009-07-23 16:30:27 UTC (rev 284658)
@@ -2407,6 +2407,7 @@
 	if (entry->is_zip && process_zip > 0) {
 		/* verify local file header */
 		phar_zip_file_header local;
+		phar_zip_data_desc desc;

 		if (SUCCESS != phar_open_archive_fp(idata->phar TSRMLS_CC)) {
 			spprintf(error, 0, "phar error: unable to open zip-based phar archive \"%s\" to verify local file header for file \"%s\"", idata->phar->fname, entry->filename);
@@ -2420,6 +2421,25 @@
 			return FAILURE;
 		}

+		/* check for data descriptor */
+		if (((PHAR_ZIP_16(local.flags)) & 0x8) == 0x8) {
+			php_stream_seek(phar_get_entrypfp(idata->internal_file TSRMLS_CC),
+					entry->header_offset + sizeof(local) +
+					PHAR_ZIP_16(local.filename_len) +
+					PHAR_ZIP_16(local.extra_len) +
+					entry->compressed_filesize, SEEK_SET);
+			if (sizeof(desc) != php_stream_read(phar_get_entrypfp(idata->internal_file TSRMLS_CC),
+							    (char *) &desc, sizeof(desc))) {
+				spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (cannot read local data descriptor for file \"%s\")", idata->phar->fname, entry->filename);
+				return FAILURE;
+			}
+			if (desc.signature[0] == 'P' && desc.signature[1] == 'K') {
+				memcpy(&(local.crc32), &(desc.crc32), 12);
+			} else {
+				/* old data descriptors have no signature */
+				memcpy(&(local.crc32), &desc, 12);
+			}
+		}
 		/* verify local header */
 		if (entry->filename_len != PHAR_ZIP_16(local.filename_len) || entry->crc32 != PHAR_ZIP_32(local.crc32) || entry->uncompressed_filesize != PHAR_ZIP_32(local.uncompsize) || entry->compressed_filesize != PHAR_ZIP_32(local.compsize)) {
 			spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (local header of file \"%s\" does not match central directory)", idata->phar->fname, entry->filename);

Modified: pecl/phar/trunk/pharzip.h
===================================================================
--- pecl/phar/trunk/pharzip.h	2009-07-23 16:28:17 UTC (rev 284657)
+++ pecl/phar/trunk/pharzip.h	2009-07-23 16:30:27 UTC (rev 284658)
@@ -37,6 +37,7 @@

 /* unused in this release */
 typedef struct _phar_zip_file_datadesc {
+	char signature[4];  /* signature (optional)            4 bytes */
 	char crc32[4];      /* crc-32                          4 bytes */
 	char compsize[4];   /* compressed size                 4 bytes */
 	char uncompsize[4]; /* uncompressed size               4 bytes */

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2009-07-23 16:28:17 UTC (rev 284657)
+++ php/php-src/branches/PHP_5_3/NEWS	2009-07-23 16:30:27 UTC (rev 284658)
@@ -26,6 +26,7 @@
 - Fixed bug #48854 (array_merge_recursive modifies arrays after first one).
   (Felipe)
 - Fixed bug #48802 (printf() returns incorrect outputted length). (Jani)
+- Fixed bug #48791 (open office files always reported as corrupted). (Greg)
 - Fixed bug #48788 (RecursiveDirectoryIterator doesn't descend into symlinked
   directories). (Ilia)
 - Fixed bug #48783 (make install will fail saying phar file exists). (Greg)

Modified: php/php-src/branches/PHP_5_3/ext/phar/phar.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/phar/phar.c	2009-07-23 16:28:17 UTC (rev 284657)
+++ php/php-src/branches/PHP_5_3/ext/phar/phar.c	2009-07-23 16:30:27 UTC (rev 284658)
@@ -2407,6 +2407,7 @@
 	if (entry->is_zip && process_zip > 0) {
 		/* verify local file header */
 		phar_zip_file_header local;
+		phar_zip_data_desc desc;

 		if (SUCCESS != phar_open_archive_fp(idata->phar TSRMLS_CC)) {
 			spprintf(error, 0, "phar error: unable to open zip-based phar archive \"%s\" to verify local file header for file \"%s\"", idata->phar->fname, entry->filename);
@@ -2420,6 +2421,25 @@
 			return FAILURE;
 		}

+		/* check for data descriptor */
+		if (((PHAR_ZIP_16(local.flags)) & 0x8) == 0x8) {
+			php_stream_seek(phar_get_entrypfp(idata->internal_file TSRMLS_CC),
+					entry->header_offset + sizeof(local) +
+					PHAR_ZIP_16(local.filename_len) +
+					PHAR_ZIP_16(local.extra_len) +
+					entry->compressed_filesize, SEEK_SET);
+			if (sizeof(desc) != php_stream_read(phar_get_entrypfp(idata->internal_file TSRMLS_CC),
+							    (char *) &desc, sizeof(desc))) {
+				spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (cannot read local data descriptor for file \"%s\")", idata->phar->fname, entry->filename);
+				return FAILURE;
+			}
+			if (desc.signature[0] == 'P' && desc.signature[1] == 'K') {
+				memcpy(&(local.crc32), &(desc.crc32), 12);
+			} else {
+				/* old data descriptors have no signature */
+				memcpy(&(local.crc32), &desc, 12);
+			}
+		}
 		/* verify local header */
 		if (entry->filename_len != PHAR_ZIP_16(local.filename_len) || entry->crc32 != PHAR_ZIP_32(local.crc32) || entry->uncompressed_filesize != PHAR_ZIP_32(local.uncompsize) || entry->compressed_filesize != PHAR_ZIP_32(local.compsize)) {
 			spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (local header of file \"%s\" does not match central directory)", idata->phar->fname, entry->filename);

Modified: php/php-src/branches/PHP_5_3/ext/phar/pharzip.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/phar/pharzip.h	2009-07-23 16:28:17 UTC (rev 284657)
+++ php/php-src/branches/PHP_5_3/ext/phar/pharzip.h	2009-07-23 16:30:27 UTC (rev 284658)
@@ -37,6 +37,7 @@

 /* unused in this release */
 typedef struct _phar_zip_file_datadesc {
+	char signature[4];  /* signature (optional)            4 bytes */
 	char crc32[4];      /* crc-32                          4 bytes */
 	char compsize[4];   /* compressed size                 4 bytes */
 	char uncompsize[4]; /* uncompressed size               4 bytes */

Modified: php/php-src/trunk/ext/phar/phar.c
===================================================================
--- php/php-src/trunk/ext/phar/phar.c	2009-07-23 16:28:17 UTC (rev 284657)
+++ php/php-src/trunk/ext/phar/phar.c	2009-07-23 16:30:27 UTC (rev 284658)
@@ -2407,6 +2407,7 @@
 	if (entry->is_zip && process_zip > 0) {
 		/* verify local file header */
 		phar_zip_file_header local;
+		phar_zip_data_desc desc;

 		if (SUCCESS != phar_open_archive_fp(idata->phar TSRMLS_CC)) {
 			spprintf(error, 0, "phar error: unable to open zip-based phar archive \"%s\" to verify local file header for file \"%s\"", idata->phar->fname, entry->filename);
@@ -2420,6 +2421,25 @@
 			return FAILURE;
 		}

+		/* check for data descriptor */
+		if (((PHAR_ZIP_16(local.flags)) & 0x8) == 0x8) {
+			php_stream_seek(phar_get_entrypfp(idata->internal_file TSRMLS_CC),
+					entry->header_offset + sizeof(local) +
+					PHAR_ZIP_16(local.filename_len) +
+					PHAR_ZIP_16(local.extra_len) +
+					entry->compressed_filesize, SEEK_SET);
+			if (sizeof(desc) != php_stream_read(phar_get_entrypfp(idata->internal_file TSRMLS_CC),
+							    (char *) &desc, sizeof(desc))) {
+				spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (cannot read local data descriptor for file \"%s\")", idata->phar->fname, entry->filename);
+				return FAILURE;
+			}
+			if (desc.signature[0] == 'P' && desc.signature[1] == 'K') {
+				memcpy(&(local.crc32), &(desc.crc32), 12);
+			} else {
+				/* old data descriptors have no signature */
+				memcpy(&(local.crc32), &desc, 12);
+			}
+		}
 		/* verify local header */
 		if (entry->filename_len != PHAR_ZIP_16(local.filename_len) || entry->crc32 != PHAR_ZIP_32(local.crc32) || entry->uncompressed_filesize != PHAR_ZIP_32(local.uncompsize) || entry->compressed_filesize != PHAR_ZIP_32(local.compsize)) {
 			spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (local header of file \"%s\" does not match central directory)", idata->phar->fname, entry->filename);

Modified: php/php-src/trunk/ext/phar/pharzip.h
===================================================================
--- php/php-src/trunk/ext/phar/pharzip.h	2009-07-23 16:28:17 UTC (rev 284657)
+++ php/php-src/trunk/ext/phar/pharzip.h	2009-07-23 16:30:27 UTC (rev 284658)
@@ -37,6 +37,7 @@

 /* unused in this release */
 typedef struct _phar_zip_file_datadesc {
+	char signature[4];  /* signature (optional)            4 bytes */
 	char crc32[4];      /* crc-32                          4 bytes */
 	char compsize[4];   /* compressed size                 4 bytes */
 	char uncompsize[4]; /* uncompressed size               4 bytes */
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to