]> granicus.if.org Git - php/commitdiff
fix remaining big-endian issues with phar
authorGreg Beaver <cellog@php.net>
Sun, 15 Feb 2009 20:29:13 +0000 (20:29 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 15 Feb 2009 20:29:13 +0000 (20:29 +0000)
ext/phar/phar.c
ext/phar/zip.c

index 45c02714e3a0017a09734c049a24cc5a084cff53..44ca1ae75ebb1878efe2637f5c482372c9f9b236 100644 (file)
@@ -510,12 +510,19 @@ void phar_entry_remove(phar_entry_data *idata, char **error TSRMLS_DC) /* {{{ */
        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); \
index c12f53b5b960eb3d8f48590f5bc3718b60f2e9f3..f0aa483d9813f3d7d087c93dc83150891f84b639 100644 (file)
@@ -383,7 +383,7 @@ foundit:
                        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 @@ foundit:
                        }
 
                        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 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, long len, int defau
        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 @@ fperror:
        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 @@ nocentralerror:
        }
 
        /* 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);
                }