cellog          Sun Feb 15 20:29:13 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/phar   phar.c zip.c 
  Log:
  fix remaining big-endian issues with phar
  
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.370.2.56&r2=1.370.2.57&diff_format=u
Index: php-src/ext/phar/phar.c
diff -u php-src/ext/phar/phar.c:1.370.2.56 php-src/ext/phar/phar.c:1.370.2.57
--- php-src/ext/phar/phar.c:1.370.2.56  Fri Jan  2 20:43:41 2009
+++ php-src/ext/phar/phar.c     Sun Feb 15 20:29:13 2009
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar.c,v 1.370.2.56 2009/01/02 20:43:41 iliaa Exp $ */
+/* $Id: phar.c,v 1.370.2.57 2009/02/15 20:29:13 cellog Exp $ */
 
 #define PHAR_MAIN 1
 #include "phar_internal.h"
@@ -510,12 +510,19 @@
        var = ((((unsigned char*)(buffer))[1]) <<  8) \
                | (((unsigned char*)(buffer))[0]); \
        (buffer) += 2
-# define PHAR_ZIP_32(buffer) ((((unsigned char*)(buffer))[3]) << 24) \
-               | ((((unsigned char*)(buffer))[2]) << 16) \
-               | ((((unsigned char*)(buffer))[1]) <<  8) \
-               | (((unsigned char*)(buffer))[0])
-# define PHAR_ZIP_16(buffer) ((((unsigned char*)(buffer))[1]) <<  8) \
-               | (((unsigned char*)(buffer))[0])
+static inline php_uint32 phar_fix_32(php_uint32 buffer)
+{
+       return ((((unsigned char *)&buffer)[3]) << 24) |
+               ((((unsigned char *)&buffer)[2]) << 16) |
+               ((((unsigned char *)&buffer)[1]) << 8) |
+               (((unsigned char *)&buffer)[0]);
+}
+static inline php_uint16 phar_fix_16(php_uint16 buffer)
+{
+       return ((((unsigned char *)&buffer)[1]) << 8) | ((unsigned char 
*)&buffer)[0];
+}
+# define PHAR_ZIP_32(buffer) phar_fix_32((php_uint32)(buffer))
+# define PHAR_ZIP_16(buffer) phar_fix_16((php_uint16)(buffer))
 #else
 # define PHAR_GET_32(buffer, var) \
        var = *(php_uint32*)(buffer); \
@@ -3626,7 +3633,7 @@
        php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
        php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION);
        php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION);
-       php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.56 $");
+       php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.57 $");
        php_info_print_table_row(2, "Phar-based phar archives", "enabled");
        php_info_print_table_row(2, "Tar-based phar archives", "enabled");
        php_info_print_table_row(2, "ZIP-based phar archives", "enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/zip.c?r1=1.47.2.26&r2=1.47.2.27&diff_format=u
Index: php-src/ext/phar/zip.c
diff -u php-src/ext/phar/zip.c:1.47.2.26 php-src/ext/phar/zip.c:1.47.2.27
--- php-src/ext/phar/zip.c:1.47.2.26    Sun Feb 15 19:22:42 2009
+++ php-src/ext/phar/zip.c      Sun Feb 15 20:29:13 2009
@@ -383,7 +383,7 @@
                        php_stream_seek(fp, loc + 
PHAR_GET_16(zipentry.extra_len), SEEK_SET);
                }
 
-               switch (zipentry.compressed) {
+               switch (PHAR_GET_16(zipentry.compressed)) {
                        case PHAR_ZIP_COMP_NONE :
                                /* compression flag already set */
                                break;
@@ -450,7 +450,7 @@
                        }
 
                        p = buf;
-                       entry.metadata_len = zipentry.comment_len;
+                       entry.metadata_len = PHAR_GET_16(zipentry.comment_len);
 
                        if (phar_parse_metadata(&p, &(entry.metadata), 
PHAR_GET_16(zipentry.comment_len) TSRMLS_CC) == FAILURE) {
                                entry.metadata_len = 0;
@@ -996,6 +996,7 @@
        char *temperr = NULL;
        struct _phar_zip_pass pass;
        phar_zip_dir_end eocd;
+       php_uint32 cdir_size, cdir_offset;
 
        pass.error = &temperr;
        entry.flags = PHAR_ENT_PERM_DEF_FILE;
@@ -1197,7 +1198,7 @@
        memset(&eocd, 0, sizeof(eocd));
 
        strncpy(eocd.signature, "PK\5\6", 4);
-       eocd.counthere = eocd.count = zend_hash_num_elements(&phar->manifest);
+       eocd.counthere = eocd.count = 
PHAR_GET_16(zend_hash_num_elements(&phar->manifest));
        zend_hash_apply_with_argument(&phar->manifest, phar_zip_changed_apply, 
(void *) &pass TSRMLS_CC);
 
        if (temperr) {
@@ -1216,11 +1217,13 @@
        }
 
        /* save zip */
-       eocd.cdir_size = php_stream_tell(pass.centralfp);
-       eocd.cdir_offset = php_stream_tell(pass.filefp);
+       cdir_size = php_stream_tell(pass.centralfp);
+       cdir_offset = php_stream_tell(pass.filefp);
+       eocd.cdir_size = PHAR_SET_32(cdir_size);
+       eocd.cdir_offset = PHAR_SET_32(cdir_offset);
        php_stream_seek(pass.centralfp, 0, SEEK_SET);
 
-       if (eocd.cdir_size != php_stream_copy_to_stream(pass.centralfp, 
pass.filefp, PHP_STREAM_COPY_ALL)) {
+       if (cdir_size != php_stream_copy_to_stream(pass.centralfp, pass.filefp, 
PHP_STREAM_COPY_ALL)) {
                if (error) {
                        spprintf(error, 4096, "phar zip flush of \"%s\" failed: 
unable to write central-directory", phar->fname);
                }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to