]> granicus.if.org Git - php/commitdiff
fix tar generation - we were subtly corrupting the header with \0 because of use...
authorGreg Beaver <cellog@php.net>
Mon, 28 Apr 2008 16:44:53 +0000 (16:44 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 28 Apr 2008 16:44:53 +0000 (16:44 +0000)
ext/phar/phar_object.c
ext/phar/tar.c

index fb1c1ff1b7988a6984b36f51a1cf374ae5580064..67992f07f5c9ace60c517d9e589c652bd91db25b 100755 (executable)
@@ -306,15 +306,10 @@ static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, ch
 
                                zend_try {
                                        zend_execute(new_op_array TSRMLS_CC);
-                                       destroy_op_array(new_op_array TSRMLS_CC);
-                                       efree(new_op_array);
-                                       if (!EG(exception)) {
-                                               if (EG(return_value_ptr_ptr)) {
-                                                       zval_ptr_dtor(EG(return_value_ptr_ptr));
-                                               }
-                                       }
                                } zend_catch {
                                } zend_end_try();
+                               destroy_op_array(new_op_array TSRMLS_CC);
+                               efree(new_op_array);
                                if (PHAR_G(cwd)) {
                                        efree(PHAR_G(cwd));
                                        PHAR_G(cwd) = NULL;
@@ -322,6 +317,12 @@ static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, ch
                                }
                                PHAR_G(cwd_init) = 0;
                                efree(name);
+                               if (EG(return_value_ptr_ptr)) {
+                                       zval_ptr_dtor(EG(return_value_ptr_ptr));
+                               }
+                               if (EG(exception)) {
+                                       zend_throw_exception_internal(NULL TSRMLS_CC);
+                               }
                                zend_bailout();
                        }
                        return PHAR_MIME_PHP;
index e8dceccac5326b166ff5556bf87905f1aa2fe76f..3afdc9126b0832f2fac440b8d21c74b956adf763 100644 (file)
@@ -435,7 +435,7 @@ int phar_tar_writeheaders(void *pDest, void *argument TSRMLS_DC)
                memcpy(header.name, entry->filename, entry->filename_len);
        }
        phar_tar_octal(header.mode, entry->flags & PHAR_ENT_PERM_MASK, sizeof(header.mode)-1);
-       if (FAILURE == phar_tar_octal(header.size, entry->uncompressed_filesize, sizeof(header.size))) {
+       if (FAILURE == phar_tar_octal(header.size, entry->uncompressed_filesize, sizeof(header.size)-1)) {
                if (fp->error) {
                        spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, filename \"%s\" is too large for tar file format", entry->phar->fname, entry->filename);
                }
@@ -450,13 +450,13 @@ int phar_tar_writeheaders(void *pDest, void *argument TSRMLS_DC)
        /* calc checksum */
        header.typeflag = entry->tar_type;
        if (entry->link) {
-               strcpy(header.linkname, entry->link);
+               strncpy(header.linkname, entry->link, strlen(entry->link));
        }
-       strcpy(header.magic, "ustar");
-       strcpy(header.version, "00");
-       strcpy(header.checksum, "        ");
+       strncpy(header.magic, "ustar", sizeof("ustar")-1);
+       strncpy(header.version, "00", sizeof("00")-1);
+       strncpy(header.checksum, "        ", sizeof("        ")-1);
        entry->crc32 = phar_tar_checksum((char *)&header, sizeof(header));
-       if (FAILURE == phar_tar_octal(header.checksum, entry->crc32, sizeof(header.checksum))) {
+       if (FAILURE == phar_tar_octal(header.checksum, entry->crc32, sizeof(header.checksum)-1)) {
                if (fp->error) {
                        spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, checksum of file \"%s\" is too large for tar file format", entry->phar->fname, entry->filename);
                }